public void OnTriggerEnter(Collider other) { GameObject cage = GameObject.Find("cage"); CageScript cageScript = cage.GetComponent <CageScript>(); //m_score = cageScript.score; if (other.tag == "cage")//pacman enters cage { GetNearest(); } if (other.transform.position == food[pointIndex - 1].transform.position) //pacman eats food { if (pointIndex == food.Length) //eat the last one { havingFood = false; noMoreFood = true; Destroy(other.gameObject); cageScript.ChangeScore(-1); //m_score--; Debug.Log("no more food."); } else { Debug.Log("i'm eating food" + pointIndex); Destroy(other.gameObject); cageScript.ChangeScore(-1); pointIndex++; Debug.Log("I'm going to eat food" + pointIndex); } } }
void OnTriggerEnter2D(Collider2D col) { HealthManager hm = col.GetComponent <HealthManager>(); if (hm != null) { hm.imhit(); } CageScript cs = col.GetComponent <CageScript>(); if (cs != null) { cs.des(); } Destroy(gameObject); }