Unity 3D: Cast Transform as Game Script Class in C#, Convert Transform or GameObject to C# Script Class

6/14/2018 7:24:47 PM

Get the C# class of a script connected to an object.

MyClassName myClassObj = transform.gameObject.GetComponent();
if (myClassObj != null)
{
     //call a function on the attached script
     myClassObj.AFunctionInThatScript();
}