Hi, a number of the built in scripts like rigidbody and networkView seem to do something like this, ie: rigidbody.AddForce(1,1,1); How could you make your own script that you could attach to a gameobject and call functions from another script on that same object like this: myscript.myfunction(); instead of: transform.GetComponent("myscript").myfunction();
thanks, but is there any way to do it without the line assigning the script to a variable? I'm trying to make components work like the built in ones and want to avoid any complexities that built in components don't have so they're as familiar as possible for people to work with
No, but you only have to do that once if you use a private variable: Code (csharp): private var myscript : MyScript; function Start () { myscript = GetComponent(MyScript); } It's better for speed to cache the reference like that anyway. --Eric