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 


To destroy a gameobject from within after 5 seconds

 Destroy(gameObject, 5);

To destroy a script instance from a gameobject


To destroy a component on a gameobject, in this example a rigidbody


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


and then put all you debugging and testing code within a similar set of hash tags thus,


    private void OnDrawGizmos()
        Debug.Log("Text: ");

        if (Application.isPlaying)
            Gizmos.color = Color.white;
            Gizmos.DrawWireSphere(mousePoint3D, 0.2f);
            Gizmos.DrawLine(transform.position, mousePoint3D);

now if you comment out the  ##define DEBUG_FILEASSIST , then all code and comments between the #if DEBUG_FILEASSIST will automatically be commented out as well. You don’t need to go through the whole file to find all your debugs and helper code. It will look like this



    private void OnDrawGizmos()
        Debug.Log("Text: ");

        if (Application.isPlaying)
            Gizmos.color = Color.white;
            Gizmos.DrawWireSphere(mousePoint3D, 0.2f);
            Gizmos.DrawLine(transform.position, mousePoint3D);

Neat eh!


public void LookAt(Transform targetVector3 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 look at the mouse pointer in a 2D top down game, I could use the following code to rotate the gameObject.

private Vector3 mousePoint3D; 

mousePoint3D = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.back * Camera.main.transform.position.z);

transform.LookAt(mousePoint3D, Vector3.back);



If you have an app where you will need to instantiate a gameobject as a child of another gameobject, then you will need to use Transform.SetParent to do this. Unity actually does a nice document on explaining this here.  But in case you don’t want to link through, here is the main bit of the code you need.

define your child which is a game object and the transform of the desired parent gameobject clip 

public GameObject child;
public Transform parent;

Then you assign/remove the child and parent in the following ways

// Sets "newParent" as the new parent of the child GameObject.

// Same as above, except worldPositionStays set to false
// makes the child keep its local orientation rather than
// its global orientation.
child.transform.SetParent(newParent, false);

// Setting the parent to ‘null’ unparents the GameObject
// and turns child into a top-level object in the hierarchy



Transforms position from world space to local space.

This function is essentially the opposite of Transform.TransformPoint, which is used to convert from local to world space.

Note that the returned position is affected by scale. Use Transform.InverseTransformDirection if you are dealing with direction vectors rather than positions.

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 no position
  • A point: position only


Vector3.back  is shorthand for   Vector3(0,0,-1);  is shorthand for writing  Vector3(0,0,0);

Vector3.left  is shorthand for   Vector3(-1,0,0);

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 fast/slow the framerate is.

And duck gives us a further explanation

FixedUpdate should be used when applying forces, torques, or other physics-related functions – because you know it will be executed exactly in sync with the physics engine itself.

Whereas Update() can vary out of step with the physics engine, either faster or slower, depending on how much of a load the graphics are putting on the rendering engine at any given time, which – if used for physics – would give correspondingly variant physical effects!

The exception to this would be that if your scene was putting such a load on the physics engine that it approaches the point where it becomes impossible to execute the required number of physics time steps to keep up to speed with ‘real time’. This means that your game has become impossible to simulate in real time – and in this case you need to seriously think about redesigning your game! This can happen if you have large numbers of complex objects (eg, rigidbody mesh colliders) all clumped together so you have lots of many-to-many collisions occuring each step.

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

Ensure that CrossPlatformInput is selected in both the “Editor” and “Standard Assets” folders.

Open up the Project Setting > Inputs to define all of the controls

To refer to the CPI from your class file you must include it at the top with

 using UnityStandardAssets.CrossPlatformInput;

Then you can reference it directly