unity c# get gameobject of script code example
Example 1: c# unity gameObject.script
void Update()
{
string Thing = gameObject.GetComponent<CustomScriptName>().Variable;
if (Thing == "String1")
{
DoStuff();
}
if (Thing == "String2")
{
DoOtherStuff();
}
}
Example 2: how to reference this gameobject unity
// use the keyword "this"
this.SetActive(true);
// the line above will set the GameObject this script is attached to active