Error playing audio and animation to unity

Viewed 21

I'm building a game that wants my player to rise when the mat hits the mat and makes a noise. I did this code in my playback source and whatever I did, only the mattress sounds and seismic animation I defined for it did not work. That is, it runs only for the first mattress, and when it hits the second and third mattresses, only the first mattress shakes. If I want to explain to other mattresses inside the player that (if my player tags the mattress) there is a lot of code. And I do not want to be busy. I also created a separate source called the trampoline and attributed it to all the mattresses. I also entered this code for the trampoline source:

        void OnCollisionEnter2D(Collision2D TagTrampolin)
        {
            if (TagTrampolin.gameObject.tag == "PlayerTAG")
            {
                MyAudio.PlayOneShot(AudioTrampolin);
                MyAnimation.Play("Anim_Larzesh");
            }
        }

        void OnCollisionExit2D(Collision2D TagTrampolin)
        {
            if (TagTrampolin.gameObject.tag == "PlayerTAG")
            {
                MyAnimation.Play("Anim_Stap");
            }
        }

(I also gave GetComponent to MyAnim and MyAudio resources, but I did not type it here because it took too long) But when the player hit the mat, the game stopped and he made two mistakes that I do not understand. I also translated them but did not say anything specific. From the empty code OnTriggerEnter2D and void OnTriggerExit2D I used it, but it gave the same error again.

If anyone knows please help me because it is very important. I apologize if I mispronounced or mispronounced a sentence because I can not speak good English.

0 Answers
Related