A simple basic script: play animation on collision

I am a big noob in scripting, but i am working on a game so i can learn it.

I am making a scary game, i placed a cube and made it invisible and that you could walk through it.
I want that if the firstpersoncontroller is walking through it, a animation has to start of a ghost that is flying towards you.
Is there a simple script that let’s you do that. Let’s say that the animation is called: Ghost1 and the cube is called: trigger1

I searched for like a hour but i only found scripts that were not compleet and because i am a noob in scripting i couldn’t get it to work.

Also, can i add a sound to the animation or do i need another script for that?

  1. make a collider on character
  2. make c collider on cube and mark it as trigger
  3. make a simple script and attach it to cube
  4. make a method that fires when something enters a trigger (Unity - Scripting API: MonoBehaviour.OnTriggerEnter(Collider))
  5. in thins method you got other collider in inputs, get a character from it using ‘collider.gameObject’
  6. apply an animation switch to character (Unity - Scripting API: Animation.CrossFade)

write here if you stuck anywhere. be ready to try it yourself and we will help to finish the task 8)