示例#1
0
文件: Egg.cs 项目: broadfire0016/STE
    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.name == "Ball" || other.gameObject.name == "Ball(Clone)")
        {
            gameObject.rigidbody.isKinematic = false;
            if (Application.loadedLevelName != "Level2" && Application.loadedLevelName != "Level3")
            {
                gameObject.transform.Translate(new Vector3(-1f, 0f, 0f));
            }
            else
            {
                gameObject.transform.Translate(new Vector3(0f, 0f, -1f));
            }
        }


        if (other.gameObject.name == "Floor" || other.gameObject.name == "Cart" || other.gameObject.name == "basketwall")
        {
            Destroy();

            if (gameObject.tag == "White Egg")
            {
                whitebrokenEgg      = GameObject.Find("WhiteBroken").GetComponent <ObjectPooler>();
                spawnWhiteBrokenEgg = whitebrokenEgg.GetPooledObject();
                spawnWhiteBrokenEgg.transform.position = new Vector3(BreakEgg.transform.position.x - 1, BreakEgg.transform.position.y, BreakEgg.transform.position.z);
                spawnWhiteBrokenEgg.SetActive(true);
                Invoke("RemoveWhiteEgg", 1f);
                audioplay.PlayBreakEgg();
            }
            if (gameObject.tag == "Gold Egg")
            {
                goldbrokenEgg      = GameObject.Find("GoldBroken").GetComponent <ObjectPooler>();
                spawnGoldBrokenEgg = goldbrokenEgg.GetPooledObject();
                spawnGoldBrokenEgg.transform.position = new Vector3(BreakEgg.transform.position.x - 1, BreakEgg.transform.position.y, BreakEgg.transform.position.z);
                spawnGoldBrokenEgg.SetActive(true);
                Invoke("RemoveGoldEgg", 1f);
                audioplay.PlayBreakEgg();
            }
            if (gameObject.tag == "Red Egg")
            {
                redbrokenEgg      = GameObject.Find("RedBroken").GetComponent <ObjectPooler>();
                spawnRedBrokenEgg = redbrokenEgg.GetPooledObject();
                spawnRedBrokenEgg.transform.position = new Vector3(BreakEgg.transform.position.x - 1, BreakEgg.transform.position.y, BreakEgg.transform.position.z);
                spawnRedBrokenEgg.SetActive(true);
                Invoke("RemoveRedEgg", 1f);
                audioplay.PlayBreakEgg();
            }
            if (gameObject.tag == "Blue Egg")
            {
                bluebrokenEgg      = GameObject.Find("BlueBroken").GetComponent <ObjectPooler>();
                spawnBlueBrokenEgg = bluebrokenEgg.GetPooledObject();
                spawnBlueBrokenEgg.transform.position = new Vector3(BreakEgg.transform.position.x - 1, BreakEgg.transform.position.y, BreakEgg.transform.position.z);
                spawnBlueBrokenEgg.SetActive(true);
                Invoke("RemoveBlueEgg", 1f);
                audioplay.PlayBreakEgg();
            }
            if (gameObject.tag == "Rotten Egg")
            {
                rottenbrokenEgg      = GameObject.Find("RottenBroken").GetComponent <ObjectPooler>();
                spawnRottenBrokenEgg = rottenbrokenEgg.GetPooledObject();
                spawnRottenBrokenEgg.transform.position = new Vector3(BreakEgg.transform.position.x - 1, BreakEgg.transform.position.y, BreakEgg.transform.position.z);
                spawnRottenBrokenEgg.SetActive(true);
                Invoke("RemoveRottenEgg", 1f);
                audioplay.PlayBreakEgg();
            }
        }
    }