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: Crosshair Problem - YouTube

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;
}

Nvm Guys, I figured it out with this video:

Thank you to anyone trying to help me :slight_smile: