void Update () {
if (goright == true) {
rig.velocity = new Vector2 (m.movespeed, rig.velocity.y);
m.anim.SetInteger ("State", 1);
}
if (goleft == true) {
rig.velocity = new Vector2 (-m.movespeed, rig.velocity.y);
m.anim.SetInteger ("State", 1);
}
}
public void ondownMoveLeft(){
goleft = true;
}
public void ondownMoveRight(){
goright = true;
}
public void onupMoveLeft(){
m.anim.SetInteger ("State", 0);
goleft = false;
}
public void onupMoveRight(){
m.anim.SetInteger ("State", 0);
goright = false;
}
i am using this code to move my character using UI buttons with the help of Event Triggers. i set it to change the animation from idle to running or from State 0 to 1 when the player moves and it does works that way but the problem is once it goes into State 1 it never comes back to State 0 but it should since i am setting the State back to 0 when the OnPointerUp
trigger gets activated. am i missing something?
OnPointerDown
is calling its respective ondown method and OnPointerUp
is calling its respective onup method. for eg, when you press the left button it calls OnPointerDown
which is set to call the method ondownMoveLeft.
i also checked with Debug.Log
and everything is being executed but still the animation State is not changing.
OnPointerUp
trigger? I don't see it in your code \$\endgroup\$onupMoveRight
etc.? How are they being called? They are not part ofMonoBehaviour
so where are you calling them? \$\endgroup\$m.anim.SetInteger ("State", 1);
being executed afterwards? Based on this code sample it will be hard to really help you - you need to use a debugger anyway. \$\endgroup\$