Unity 3D – CSharp – Event Functions – Inizialization – Update – GUI – Mouse – Physics

To create videogames Unity3D give us special functions to manage special operations as variable inizialization, updating, physic management.


using UnityEngine;
using System.Collections;

public class MyScript : MonoBehaviour
{

        // Initialization Events
        // ******************************************

	void Awake ()
	{
		// first inizialization
		Debug.Log("Awake called.");
	}
	
	
	void Start ()
	{
		// second inizialization
		Debug.Log("Start called.");
	}

        // Regular Update Events
        // ******************************************

	void FixedUpdate ()
	{
		// frame indipendent update
                // use this function to drive physic
		Debug.Log("FixedUpdate time :" + Time.deltaTime);
	}
	
	void Update ()
	{
		// update at every frame
		Debug.Log("Update time :" + Time.deltaTime);
	}

	void LateUpdate () 
	{
		// update at the end of the frame rendering
		Debug.Log("Late Update");
	}

        // GUI Events
        // ******************************************

        void OnGUI() 
        {
                // draw here labels, buttons and other Graphic User Interface elements
        	GUI.Label(labelRect, "Game Over");
        }

        // Mouse Events
        // ******************************************

        void OnMouseOver() 
        {
                // do something if mouse is over
        }

        void OnMouseDown() {
                // do something if mouse is down
        }

        // Physics Events
        // ******************************************

        void OnCollisionEnter(otherObj: Collision) 
        {
                // do stuff if there is a collision
        }

        void OnTriggerEnter(Collider other) 
        {
                // do stuff if there is an object that overlap the trigger
        }

} // END MyScript

My website: http://www.lucedigitale.com

Ref: http://docs.unity3d.com/Manual/EventFunctions.html