示例#1
0
        //OnTriggerEnter2D is sent when another object enters a trigger collider attached to this object (2D physics only).
        private void OnTriggerEnter2D(Collider2D other)
        {
            //Check if the tag of the trigger collided with is Exit.
            if (other.tag == "Exit")
            {
                //Invoke the Restart function to start the next level with a delay of restartLevelDelay (default 1 second).
                Invoke("Restart", restartLevelDelay);

                //Disable the player object since level is over.
                enabled = false;
            }

            ElementProperty tar_script = other.transform.GetComponent <ElementProperty> ();

            if (tar_script != null && (tar_script.index.first >= 0 && tar_script.index.second >= 0))
            {
                if (tar_script.type == ElementType.food)                 //人物捡到食物
                {
                    SoundManager.instance.RandomizeSfx(eatSound1, eatSound2);
                    tar_script.DoEffect(this);
                }
                else if (tar_script.type == ElementType.item)                   //人物捡到道具
                {
                    BagSystem.instance.AddItem(tar_script.index);
                    tar_script.Destroy();
                }
                else                  //人物触发剧情
                {
                    ResourcesManager.instance.storiesPool [tar_script.index.first] [tar_script.index.second].effect.Call(this);
                }
            }

            /*//Check if the tag of the trigger collided with is Food.
             * else if(other.tag == "Food")
             * {
             *      //Add pointsPerFood to the players current food total.
             *      food += pointsPerFood;
             *
             *      //Update foodText to represent current total and notify player that they gained points
             *      foodText.text = "+" + pointsPerFood + " Food: " + food;
             *
             *      //Call the RandomizeSfx function of SoundManager and pass in two eating sounds to choose between to play the eating sound effect.
             *      SoundManager.instance.RandomizeSfx (eatSound1, eatSound2);
             *
             *      //Disable the food object the player collided with.
             *      other.gameObject.SetActive (false);
             * }
             *
             * //Check if the tag of the trigger collided with is Soda.
             * else if(other.tag == "Soda")
             * {
             *      //Add pointsPerSoda to players food points total
             *      food += pointsPerSoda;
             *
             *      //Update foodText to represent current total and notify player that they gained points
             *      foodText.text = "+" + pointsPerSoda + " Food: " + food;
             *
             *      //Call the RandomizeSfx function of SoundManager and pass in two drinking sounds to choose between to play the drinking sound effect.
             *      SoundManager.instance.RandomizeSfx (drinkSound1, drinkSound2);
             *
             *      //Disable the soda object the player collided with.
             *      other.gameObject.SetActive (false);
             * }*/
        }