Destroy – Unity

public static void Destroy(Object obj, float t = 0.0F); The Unity docs have a good description of the Destroy method here. But in case you just want some quick code here it is. To destroy a gameobject from within itself, just call  Destroy(gameObject); To destroy a gameobject from within after 5 seconds Destroy(gameObject, 5); To destroy a script instance from a gameobject Destroy(this); To … Read more

Invoke – unity

public void Invoke(string methodName, float time); It calls the method methodName in time seconds  This is an alternative to using coroutines.

Mouse Position – Unity

Code to get the Mouse Position in a 2D app Vector3 mPos = Input.mousePosition; mPos.z = -Camera.main.transform.position.z; Vector3 targetPos = Camera.main.ScreenToWorldPoint(mPos);   Then to make something face towards it. yourGameObject.transform.LookAt(targetPos);

Debugging – Unity

There is a really neat way that you can turn on and off all your assistant testing code in a file. At the top of your file put the following code #define DEBUG_FILEASSIST and then put all you debugging and testing code within a similar set of hash tags thus, #if DEBUG_FILEASSIST     private void OnDrawGizmos()     {         Debug.Log(“Text: “);         if (Application.isPlaying) … Read more

Transforms – Unity

Transform.LookAt public void LookAt(Transform target, Vector3 worldUp = Vector3.up); Rotates the transform so the forward vector points at /target/’s current position. Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp vector. If you leave out the worldUp parameter, the function will use the world y axis.  So if I want the gameObject to … Read more

Vector3 – Code Theory

This is just going to be a post about things I pick up as I study   So what is a vector3? It most often describes one of two things huacanacha describes it thus : A Vector3 is a 3-tuple (an ordered list of 3 values) which can represent: A vector: direction and magnitude, but … Read more

Update v FixedUpdate – Unity

Thank you Unity Answers for giving me the low down on this one. Read the full thread HERE eric5h5 gives us a quick answer Update runs once per frame. FixedUpdate can run once, zero, or several times per frame, depending on how many physics frames per second are set in the time settings, and how … Read more

Cross Platform Input Manager – Unity

To use the cross platform input manager you need to make sure you have the Standard Assets Package included in your Unity project. To import it, use these instructions https://docs.unity3d.com/560/Documentation/Manual/AssetPackages.html Ensure that CrossPlatformInput is selected in both the “Editor” and “Standard Assets” folders. Open up the Project Setting > Inputs to define all of the … Read more