Month: April 2015

  • Making reusable functions in Unity

    One of the core fundamentals of programming. Here’s an example: public void randomX(GameObject obj){         GameObject wall = GameObject.Find (“wallLeft”);         Vector2 fullScreen = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width,Screen.height));         //world point calculations         float wallWidth = wall.GetComponent<Renderer> ().bounds.size.x;         float objWidth = obj.GetComponent<Renderer> ().bounds.size.x;         float widthRange = fullScreen.x – wallWidth-objWidth/2;         float ranX = Random.Range (-widthRange, widthRange);         obj.transform.position = new Vector2 (ranX, obj.transform.position.y);     } This function gives a game object a random x position on the screen. It takes into consideration padding on the sides (in this case, a wall on both sides) as well as the width of…

  • Doing Consistent Jumps in Unity

    So in Demonfall I wanted the guy to fall, hit the platform, jump back up to the top and then fall again. I wanted the same height jump each time. This doesn’t work by default when you turn the global gravity on. The guy’s first jump would be very short (because he fell from the…

  • Demonfall Week 2 Progress

      So, we got the left and right GUI Repeat Buttons buttons working now (the dark blue buttons with the <- and -> text in them. They’re actually more of a semi-transparent grey but they’re on top the 2 blue blocks marked with a X which are the walls. I will probably have to increase…

  • Accessing code from other scripts in Unity

    For example in one script we store the number for the score as well as the function to update the score on screen. In this example it’s called gameCode.cs and it would go something like this: public int score = 0; public void updateScore(){         GameObject labelScore = GameObject.Find (“labelScore”);         labelScoreText = labelScore.GetComponent<GUIText> ();         labelScoreText.text = “SCORE: “+score /*score.ToString ()*/;     } To access this code in another script, you would do something…

  • Allowing WordPress to accept more uploadable file formats

    I was trying to update a html file I uploaded and got the error: File type does not meet security guidelines. Try another. Very annoying. Luckily googling led me to the solution fairly easily. In the functions.php file in your theme add this add_filter(‘upload_mimes’, ‘custom_upload_mimes’); function custom_upload_mimes ( $existing_mimes=array() ) {     // add your…

  • Unity to Android checklist

    After Unity to Windows 8 Checklist and Unity to iOS Checklist, this is the Andriod version: To test on Andriod devices you will need to download the ‘Andriod SDK’ which also requires “Java SE Development Kit”. you need to download a “platform” from your Andriod SDK folder under “tools/andriod”. After that, still in your SDK…

  • Gravity and Hit Detection in Unity

    To add gravity to your main hero (for example) so he falls to physics: Place the image of the character into the scene and in the inspector click ‘add component’ and select ‘box collider 2d’ or circle collider 2d’ depending on the shape you want to have. Add the component ‘Rigidbody 2D’, so the object…

  • Demonfall Week 1 Progress

    Going to try recording my progress each week mainly as a motivator to get things done. Here’s week one: So we have the guy character. He’s affected by the global gravity and is constantly falling. When he hits the platform he jumps back up. The 2 X boxes the left and right are the controls,…

  • Side Ads

    This little demo puts promotional ads on the left and right of the webpage. To do this, the HTML is structure is like this: <body> <div id=”mainContainer”>     Main Website Content. </div> <div class=”adContainer”>     <div class=”leftAd”><a href=”http://www.google.com” target=”_blank”>left ad text</a>     </div>     <div class=”rightAd”><a href=”http://www.google.com” target=”_blank”>right ad text</a>     </div>    </div> </body>…

  • HTML Email Template

    Below is a link to a HTML file that has some CSS and code for starting a mobile friendly email. Here are also some tips: Don’t use margins: Outlook doesn’t like it Padding: give the containing table a width but no padding and then the inner table’s data cell padding but no width. No padding on…