Question by
Jmartino22 · Feb 10, 2017 at 07:31 PM ·
animationgames
How do I make Animations play on key click & then stop after?
public class movementScrit : MonoBehaviour { public float moveSpeed;
// Use this for initialization
void Start()
{
GetComponent<Animation>().wrapMode = WrapMode.Once;
}
// Update is called once per frame
void Update ()
{
//Gets key and which direction it would move in based on click.
if (Input.GetKey(KeyCode.A))
{
transform.Translate(new Vector3(-moveSpeed, 0, 0) * Time.deltaTime);
GetComponent<Animation>().Play("bossAttack");
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(new Vector3(moveSpeed, 0, 0) * Time.deltaTime);
}
if (Input.GetKey(KeyCode.W))
{
transform.Translate(new Vector3(0, moveSpeed, 0) * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(new Vector3(0, -moveSpeed, 0) * Time.deltaTime);
}
}
}
this is my code. I've realized animation.Play; no longer works, so I have attempted using this method, but nothing happens.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612110802im_/https://answers.unity.com/themes/thub/images/avi.jpg)