Skip to main content

Posts

Showing posts from September, 2013

Best Homing Missile in Unity

Today I finally found the best homing missile solution that i was searching for a long time. Since i like to collect good things, that is why i am posting this script here, in my blog.  Thanks to JamesLeeNZfor providing such a awesome script.

Here is the unity forum link. http://forum.unity3d.com/threads/196584-quot-Homing-Missile-quot-Script-problem/page2

#pragma strict
var _velocity : float = 10;
var _torque: float = 5;
var _target : Transform;
var _rigidbody : Rigidbody;


function Start()
{
           _rigidbody = transform.rigidbody;
           Fire();
}


function Fire()
{
var distance = Mathf.Infinity;
for (var go : GameObjectinGameObject.FindGameObjectsWithTag("Enemy"))
          { 
var diff = (go.transform.position - transform.position).sqrMagnitude;    if(diff < distance)                     {
                             distance = diff;
                            _target =  go.transform;
                    }
          }
}


function FixedUpdate()
{
if(_target == null || _rigi…

Unity Joystick.cs

Here is the conversion of Unity Joystick.js ( Javascript ) to Joystick.cs (csharp). I too found the solution on the internet but i am re-posting this because i found this solution after searching a lot and trying lots of non working solutions.
I used this script with Unity 4.1 ios and its working very well and exactly as Unity Joystick.js.

Here is the Original link where i found the solution thanks to him.

http://www.chrisdanielson.com/2011/05/17/unity3d-joystick-script/


using UnityEngine;    [RequireComponent(typeof(GUITexture))]  publicclass Joystick : MonoBehaviour { 

class Boundary {  publicVector2 min = Vector2.zero;  publicVector2 max = Vector2.zero;  }  

privatestaticJoystick[] joysticks;

// A static collection of all joysticks privatestaticbool enumeratedJoysticks = false;

privatestaticfloat tapTimeDelta = 0.3f;

// Time allowed between taps publicbool touchPad;

publicVector2 position = Vector2.zero;

publicRect touchZone;

publicVector2 deadZone = Vector2.zero;

// Control when position is outp…

how to show loading bar in unity

This script was specially designed for iphone , but you can put your own values. Drag a texture to the progressBar variable, and than play and click on the Stage1 Button now you can see the loading bar, remember," if your loading level is small in size than you can hardly see the loading bar but if its large than you can see the bar progressing from 0 to 100 also do add the Stage01 scene to your build settings... Enjoy!
var originalWidth = 640.0;  var originalHeight = 1136.0; privatevar scale: Vector3; var progressBar : Texture2D; privatevar async : AsyncOperation;
privatevar progress : float;

function OnGUI() {     scale.x = Screen.width/originalWidth;      scale.y = Screen.height/originalHeight;      scale.z = 1; var svMat = GUI.matrix;  GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale); if(async)     {          progress = async.progress; GUI.DrawTexture(Rect(220,1000, 200 * Mathf.Clamp01(progress), 25), progressBar);     } if(GUI.Button(Rect(50,474,100,50),"Stage1")) …