So the whole script is pretty long but basically I have an object which when you tap it calls the currency method:
if (Input.touchCount >= 1) {
hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint ((Input.GetTouch (0).position)), Vector2.up);
//On touch
if (hit.collider != null && hit.collider.tag == "bug" && Input.GetTouch (0).phase == TouchPhase.Began) {
Currency();
hit.transform.gameObject.SetActive (false);
changesprite ();
spritetransform = true;
}
This is my code inside my currency method:
if(isapple == true)
{
A1.GetComponent<SpriteRenderer>().sprite = apple;
}
if(iscoin == true)
{
A1.GetComponent<SpriteRenderer>().sprite = coin;
}
C1.transform.position = new Vector2(hit.transform.position.x, hit.transform.position.y);
StartCoroutine(C1handler());
return;
The problem is inside my coroutine:
public IEnumerator C1handler()
{
C.SetBool("startABT", true);
C1avail = true;
yield return new WaitForSeconds (0.1f);
Debug.Log("time exceeded");
C.SetBool("startABT", false);
C1avail = true;
}
Most of the time the game randomly skips calling this line:
C.SetBool("startABT", false);
Anyone know what the problem could be? Any ideas/answers are greatly appreciated. Thanks!