I'm trying to make an animated crosshair.
Hi,
I'm trying to make an animated crosshair for my fps shooter game but I keep getting the problem of the animation looping and messing up and overlapping and start another loop eventually making the crosshair going from out to in then back out instead of out than in. Does anyone have any ideas what to do to make the crosshair move out then back in when I click my mouse? Here is a video of the problem: https://www.youtube.com/watch?v=7OjLPNRDhSg&feature=youtu.be
Also I know that if I get: yield return new WaitForSeconds(0.167f); correct down to the exact number it would work but that would be an infinite number. I don't know what to do.
Here is my code:
public GameObject UpCurs;
public GameObject DownCurs;
public GameObject LeftCurs;
public GameObject RightCurs;
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1")) {
UpCurs.GetComponent<Animator> ().enabled = true;
DownCurs.GetComponent<Animator> ().enabled = true;
LeftCurs.GetComponent<Animator> ().enabled = true;
RightCurs.GetComponent<Animator> ().enabled = true;
StartCoroutine(WaitingAnim());
}
}
IEnumerator WaitingAnim () {
yield return new WaitForSeconds(0.167f);
UpCurs.GetComponent<Animator> ().enabled = false;
DownCurs.GetComponent<Animator> ().enabled = false;
LeftCurs.GetComponent<Animator> ().enabled = false;
RightCurs.GetComponent<Animator> ().enabled = false;
}
Answer by Matt246go · Mar 06, 2018 at 01:08 AM
Nvm Guys, I figured it out with this video:
https://www.youtube.com/watch?v=a_JLqIrz5YA&t=88s
Thank you to anyone trying to help me :-)