I want to stop movement of character while i call animation like Kick Jump Punch etc.. Please help
public GameObject Player; public float xMove; public float yMove; private Rigidbody myBody; private Animator anim;
void Awake()
{
myBody = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
PlayerMovement();
AnimatePlayerWalk();
PunchAnimation();
KickhAnimation();
}
public void PlayerMovement()
{
xMove = Input.GetAxis("Horizontal") * Time.deltaTime * 200;
yMove = Input.GetAxis("Vertical") * Time.deltaTime * 5;
yMove = Mathf.Clamp01(yMove); // mathf.clamp01 will move char forward but not backward
transform.Rotate(0, xMove, 0);
transform.Translate(0, 0, yMove);
}
void Walk(bool move)
{
anim.SetBool("Movement", move);
}
public void AnimatePlayerWalk()
{
if (Input.GetAxisRaw("Horizontal") != 0 ||
Input.GetAxisRaw("Vertical") > 0)
{
Walk(true);
}
else
{
Walk(false);
}
}
public void PunchAnimation()
{
if (Input.GetKeyDown(KeyCode.Z))
{
anim.SetTrigger("Punch1");
}
else if (Input.GetKeyDown(KeyCode.X))
{
anim.SetTrigger("Punch2");
}
}
public void KickhAnimation()
{
if (Input.GetKeyDown(KeyCode.C))
{
anim.SetTrigger("Kick1");
}
else if (Input.GetKeyDown(KeyCode.V))
{
anim.SetTrigger("Kick2");
}
}
}
Comment
Best Answer
Answer by Kikatzu · Sep 04, 2019 at 11:53 AM
You can use a conditional return in your movement routine to jump out. E.g.:
public void PlayerMovement() {
if(anim.GetBool("Punch1") || anim.GetBool("Punch2") ... )
return;
//your code
}