How to access gameobject by C# script

How to access gameobject by C# script

Tutorial posted over 8 years ago

If you want to access any gameobject from your scene by C# script use this method .

Step 1

First create an empty gameobject by right click on hierarchy area (on scene files).Then select empty gameobject.

Step 2

Step 3

Step 4

write this code :-

GameObject xyz;

void Start()

{

xyz=GameObject.Find("YourGameObjectName");

//now you can do any stuff with ur gameobject

}

Comments

wafelek wrote
wafelek
Great tutorial. Thanks
kuddus wrote
kuddus
Спасибо
  • Views 763
  • Likes 0
  • Comments 2

Share tutorial

Software:Category:Tags:
  • unity
Chat