Advertisement
Guest User

Unity MonoBehaviour Template for Beginners

a guest
Jan 18th, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.93 KB | None | 0 0
  1. // You can uncomment either of these enable their functionality
  2. //#define USE_SOLID_COLLISION
  3. //#define USE_TRIGGER_COLLISION
  4.  
  5. using UnityEngine;
  6. using System.Collections.Generic;
  7.  
  8. /**
  9.  * TODO: Comment what this class does.
  10.  * Note:  The name of your class must match your file name
  11.  */
  12. public class MonoBehaviourTemplate : MonoBehaviour
  13. {
  14.     // An example of a string that is editable by designers in the scene
  15.     //public string             _myString;
  16.    
  17.     // An example of an integer that is NOT editable by designers in the scene (changed only through code).
  18.     //protected int             _myInt;
  19.    
  20.     // An example of referencing multiple other gameObjects.  It is editable by designers.
  21.     //public List<GameObject>       _otherGameObjects;
  22.    
  23.     /**
  24.      * Awake is called ONCE whenever an object first becomes enabled.  This call preceeds the OnEnable call.
  25.      * Use this call for single-use initialization that will remain throughout the lifetime of an Object.
  26.      */
  27.     void Awake()
  28.     {
  29.     }
  30.    
  31.     /**
  32.      * OnEnable is called whenever BOTH this Component and the GameObject on which it resides are enabled.
  33.      * This is true by default, so by default this will run as soon as the scene starts up or a prefab is instantiated.
  34.      */
  35.     void OnEnable()
  36.     {
  37.     }
  38.    
  39.     /**
  40.      * OnDisable is called whenever EITHER this Component or its GameObject are disabled.
  41.      * It may not be obvious, but this happens whenever a GameObject gets destroyed.
  42.      * In this function, you should "undo" anything you did in OnEnable.
  43.      */
  44.     void OnDisable()
  45.     {
  46.     }
  47.    
  48.     /**
  49.      * Update gets called every frame. If you need to keep track of the time passed, use Time.deltaTime.
  50.      */
  51.     void Update()
  52.     {
  53.     }
  54.    
  55.     /**
  56.      * LateUpdate gets called every frame after all physics and animations have been computed.
  57.      * Typically, you put Camera movement in here as you want it to be computed last.
  58.      */
  59.     void LateUpdate()
  60.     {
  61.     }
  62.    
  63.     /**
  64.      * FixedUpdate is called every "Physics-Tick".  This means it can be called multiple times a frame, or none at all.
  65.      * Use this function to move any physical objects (e.g. If you have a RigidBody attached to a GameObject, put your rigidBody.Move here).
  66.      * To keep track of time passed, use Time.fixedDeltaTime.
  67.      */
  68.     void FixedUpdate()
  69.     {
  70.     }
  71.  
  72.     /**
  73.      * This is the Collision Section.  Uncomment a #define at the top if you want this Behaviour to handle collision events.
  74.      *
  75.      * Rules for Collisions:
  76.      *
  77.      *  1. The collider must be attached to the same GameObject this Component is on (e.g. no listening to the parent).
  78.      *  2. One of the colliders (this GameObject, the other, or both) must have a RigidBody (e.g. can't manually move one into another and expect this to work).
  79.      *  3. You should only use Solid Collisions OR Trigger Collisions, not both.  If you need both, make two separate GameObjects with a common parent.
  80.      */
  81. #if USE_SOLID_COLLISION && USE_TRIGGER_COLLISION
  82.     #error You just violated Rule #3.  You should only be using Solid Collision OR Trigger Collision, not both.
  83. #elif USE_SOLID_COLLISION
  84.     /**
  85.      * OnCollisionEnter is called whenever contact first happens with another collider.
  86.      */
  87.     void OnCollisionEnter(Collision collisionInfo)
  88.     {
  89.     }
  90.    
  91.     /**
  92.      * OnCollisionExit is called whenever one collider stops touching another collider.
  93.      */
  94.     void OnCollisionExit(Collision collisionInfo)
  95.     {
  96.     }
  97.    
  98.     /**
  99.      * OnCollisionStay is called throughout the duration of contact with another collider.
  100.      */
  101.     void OnCollisionStay(Collision collisionInfo)
  102.     {
  103.     }
  104. #elif USE_TRIGGER_COLLISION
  105.     /**
  106.      * OnTriggerEnter is called when one collider first enters the volume of a trigger collider.
  107.      */
  108.     void OnTriggerEnter(Collider otherCollider)
  109.     {
  110.     }
  111.    
  112.     /**
  113.      * OnTriggerExit is called when one collider exits the volume of another collider.
  114.      */
  115.     void OnTriggerExit(Collider otherCollider)
  116.     {
  117.     }
  118.    
  119.     /**
  120.      * OnTriggerStay is called when on collider is inside the volume of another collider.
  121.      */
  122.     void OnTriggerStay(Collider otherCollider)
  123.     {
  124.     }
  125. #endif
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement