Posts

Showing posts with the label gameObject

Finding a GameObject by C# script in unity

 There are main three ways of finding a gameObject in scene by script GameObject.Find() mehod You can pass string name in it and it will then search for that name in scene gameObject and return very first name which exactly match with it. using   System . Collections ; using   System . Collections . Generic ; using   UnityEngine ; public   class   test  :  MonoBehaviour {      private   GameObject  player;      // Start is called before the first frame update      void   Start ()     {          player  =  GameObject . Find ( "main_character" );          Debug . Log ( player );     } } In this example code we have declare a private GameObject and then we assign it by calling find() method. if there is exact ...