c# - Different scripts communicating too late -
public gameobject target; private rigidbody2d targetrb2d; private rigidbody targetrb; private void push() { switchkinematic(); direction = -arrow.direction; float amount = mathf.clamp((forceamount(force) * distance), 0f, 50000f); if (target.getcomponent<rigidbody2d>() != null) { targetrb2d.addforce(amount * direction, forcemode2d.force); } if (target.getcomponent<rigidbody>() != null) { targetrb.addforce(amount * direction, forcemode.force); } startcoroutine(attackswitch()); } private void pull() { switchkinematic(); direction = target.transform.position - transform.position; direction = direction.normalized; float amount = mathf.clamp(-forceamount(force), -20000f, 20000f); if (target.getcomponent<rigidbody2d>() != null) { targetrb2d.addforce(amount * direction, forcemode2d.force); } if (target.getcomponent<rigidbody>() != null) { targetrb.addforce(amount * direction, forcemode.force); } } private void switchkinematic() { if (target.getcomponent<interactiveobjecttype>() != null) { if (target.getcomponent<interactiveobjecttype>().stopped) { target.getcomponent<interactiveobjecttype>().stopped = false; } } }
push()
happening on mouse0 input uppull()
happening on mouse1 input held
i have 2 scripts communicating each other switch rigidbody.iskinematic
on , off via boolean check on 1 side. method above 1 telling other one's rigidbody become dynamic while it's kinematic.
this working fine should(have checked through debugger showing lines happening in order), problem here while push()
's commands operating in order should other script receiving method's boolean toggle seems late. therefore lines happening while switchkinematic()
didn't affect other code toggle boolean yet.
my understanding due timing of commands happening since separate scripts, not sure how resolve this. i've included similar method in script; pull()
. pull()
switching receiving end's boolean , bodytype without problem since it's updated every frame, push()
happens on keyup
, need kept way.
Comments
Post a Comment