c# - Cannot use a boolean variable from another script Unity3d -
i have code makes object rotate, , working ok if call within script.
scripta
public class ship : monobehaviour { private bool torotate=false; public void enemyrotate() { torotate = true; debug.log("er "+ torotate); } void update () { if (torotate) { transform.rotatearound(player.transform.position, vector3.forward, 100 * time.deltatime); } }
if call enemyrotate within scripta, sure enough rotation, , debug log shows variable has been set true. if call function this:
script b
public class projectile : monobehaviour { public ship ship_object; void start(){ ship_object=gameobject.addcomponent<kanaship> (); } void callfunction(){ ship_object.enemyrotate() } }
if call callfunction, debug log saying variable has been set true, rotation animation not working @ all. have tried different variants of cannot figure out im doing wrong. have used public bool , tried set true script nothing.
i recommend avoid accessing private vars (use interface if necessary), better way declare function following , pass proper boolean parameter:
void update (bool torotate) { if (torotate) { transform.rotatearound(player.transform.position, vector3.forward, 100 * time.deltatime); } }
in case, comment off line:
//private bool torotate=false;
hope help. rgds,
Comments
Post a Comment