Okay so I have created a player archer character which when he using the arrow keys,faces faces those directions and upon hitting space when in that direction,the the bow attack animation is played.
when I unpress an arrow key,the the character always returns to his default direction and when I press space when no arrow key is pressed,the the right bow attack animation is played and also when i press the up arrow key and the space bar,the the up bow attack animation does not play and instead again,the right bow attack animation is played.
I have looked at everything again and again but iI can't seem to find anything wrong.the The animation's assigned are okay and the code is okay too. Don't know whatswhat's wrong. I have been stuck at this problem all day.
my blend tree in the idle state is here
and so far,this this is my script:
using UnityEngine;
using System.Collections;
public class
PlayerDirectionAndShooting : MonoBehaviour {
Rigidbody2D rbody;
Animator anim;
// Use this for initialization
void Start () {
rbody = GetComponent<Rigidbody2D> ();
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
Vector2 direction_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
anim.SetFloat("input_x", direction_vector.x);
anim.SetFloat("input_y", direction_vector.y);
if (Input.GetKeyDown("space"))
{
if (anim.GetFloat("input_x") <= -1)
{
anim.SetBool("is_shooting_left", true);
}
}
else
{
anim.SetBool("is_shooting_left", false);
};
if (Input.GetKeyDown("space"))
{
if (anim.GetFloat("input_y") <= -1)
{
anim.SetBool("is_shooting_down", true);
}
}
else
{
anim.SetBool("is_shooting_down", false);
};
if (Input.GetKeyDown("space"))
{
if (anim.GetFloat("input_y") <= 1)
{
anim.SetBool("is_shooting_up", true);
}
}
else
{
anim.SetBool("is_shooting_up", false);
};
if (Input.GetKeyDown("space"))
{
if (anim.GetFloat("input_x") <= 1)
{
anim.SetBool("is_shooting_right", true);
}
}
else
{
anim.SetBool("is_shooting_right",false);
};
}
}