c# - Reference to function from another script -
c# - Reference to function from another script -
i have problem referencing function script. dont know do. searched solution, didn't understand that. can i'm doing wrong?
first script[dotykxd.cs]:
using unityengine; using system.collections; public class dotykxd : monobehaviour { void start() { } // utilize initialization // update called 1 time per frame void update () { if(input.touches.length <=0) { } else{ for(int i=0; i< input.touchcount;i++) { if(this.guitexture.hittest(input.gettouch(i).position)) {/* if(input.gettouch(i).phase == touchphase.began) { camera.main.backgroundcolor=color.black; }*/ if(input.gettouch(i).phase == touchphase.ended) { obrot obrotek= getcomponents<obrot> (); obrot.obr(); } } } } } }
another script[obrot.cs]
using unityengine; using system.collections; public class obrot : monobehaviour { public float speed = 5f; // update called 1 time per frame void update () { obr (); } void obr () { transform.translate(new vector3(1,0,0) * speed * time.deltatime); } }
to phone call function script need have reference gameobject or script component attached gameobject.
if have reference gameobject can utilize sendmessage this:
gameobjreference.sendmessage("nameoffunction");
if have reference script can phone call function this:
scriptreference.functionname();
however, bigger problem going be, how these references.
gameobject gameobjreference = gameobject.find("name of gameobject in scene");
that is, set name of gameobject, ever called in scene.
the other method similar.
scriptname scriptreference = gameobject.find("name of gameobject").getcomponent<scriptname>();
c# function reference unity3d
Comments
Post a Comment