示例#1
0
    public static void PlayTrapSound()
    {
        TrapSound soundSource = GameObject.FindObjectOfType <TrapSound>();

        soundSource.GetComponent <AudioSource>().volume = soundEffectVolume * 0.2f;
        soundSource.GetComponent <AudioSource>().Play();
    }
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "obs")
        {
            this.GetComponent <Rigidbody2D>().velocity        = Vector3.zero;
            this.GetComponent <Rigidbody2D>().angularVelocity = 0;
            this.GetComponent <Image>().enabled = false;

            GameObject.Find("Top_Obstacle").GetComponent <BoxCollider2D>().enabled    = false;
            GameObject.Find("Bottom_Obstacle").GetComponent <BoxCollider2D>().enabled = false;
            GameObject.Find("Left_Obstacle").GetComponent <BoxCollider2D>().enabled   = false;
            GameObject.Find("Right_Obstacle").GetComponent <BoxCollider2D>().enabled  = false;

            this.transform.GetChild(0).GetComponent <ParticleSystem>().Play();
            this.transform.GetChild(1).GetComponent <TrailRenderer>().Clear();
            this.transform.GetChild(1).GetComponent <TrailRenderer>().time = 0;

            this.gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll;
            this.gameObject.GetComponent <BoxCollider2D>().enabled   = false;

            GameOverController.GameOver();

            GameSound.Pause();
            TrapSound.Play();
        }

        else if (coll.gameObject.tag == "bounce")
        {
            BounceSound.Stop();
            BounceSound.Play();
        }
    }