- Home /
Animation Parameters Not Working Correctly
When playing my scene, the animation parameter moveSpeed, is constantly staying 0. However, the character in question still moves as set while playing his Casting Animation? I've not been able to find the answer to this problem and would appreciate the help!
Walk Animation -TRANSITION- Cast Animation if moveSpeed is equal to 0. Cast Animation - TRANSITION- Walk Animation if moveSpeed is not equal to 0.
(Side Note: If anyone can provide code in order to re-initiate movement after colliding once again with box-collider/area-effector, that would be fantastic!)
public class EnemyMovement : MonoBehaviour {
public float moveSpeed = 2; //per second
Vector3 moveDirection = new Vector3(-1, 0, 0);
bool movingLeft = false;
bool facingRight = true;
Animator anim;
void Start ()
{
//anim = GetComponent<Animator>();
}
void FixedUpdate ()
{
if (!movingLeft && !facingRight)
Flip ();
else if (movingLeft && facingRight)
Flip ();
}
void Update ()
{
if (!movingLeft && transform.localPosition.x <= -4) {
moveDirection = new Vector3 (1, 0, 0);
movingLeft = true;
}
if (movingLeft && transform.localPosition.x >= 4) {
moveDirection = new Vector3 (-1, 0, 0);
movingLeft = false;
}
transform.Translate (moveSpeed * Time.deltaTime * moveDirection);
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.name == "Character") {
moveSpeed = 0;
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
2D Animations Scaling Away From The Floor 0 Answers
2D animation diferent right and left 0 Answers
Animator State Freezing 0 Answers
How to optimize 2D Animations created with 2D Animation packege? (v3.1.1) 0 Answers