//收集物品,碰撞觸發器 private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Collection") { CherryAudio.Play(); collision.GetComponent <Animator>().Play("isGot"); // Destroy(collision.gameObject); // cherry+=1; // CherryNum.text=cherry.ToString(); } }
//角色与其他gameObject碰撞 private void OnTriggerEnter2D(Collider2D collision) { //物品收集 if (collision.tag == "Collection") { Destroy(collision.gameObject); Cherry += 1; CherryNum.text = Cherry.ToString(); CherryAudio.Play(); } //与死亡触发器碰撞 if (collision.tag == "DeadLine") { GetComponent <AudioSource>().enabled = false; Invoke("Restart", 1f);//场景重置延迟 } }