Hey guys i’m currently having a bit of trouble with some script. Any help will be hugely appreciated. I’m new to Unity and scripting so It might just be a basic error.

Right so what I’m trying to do is have a switch which is out of reach of the player, the player has to use their projectile to hit the switch which activates an animation to open a bridge.

I Keep getting an error, something on the lines of: missing component exception: there is no “animation” attatched to the “projectile” game object

as another note, the projectiles are under a tag, as players can use different projectiles.

Below is my code:

var Bridge2 : AnimationClip; 

var bridge : GameObject; 

function OnTriggerEnter (collision : Collider)

{
	if (collision.gameObject.tag == "Projectile")
	{
    		 collision.animation.Play ("Bridge2"); 
     
	}

}

From what I can understand of your code, this script is attached in the switch. In this case, you are trying to animate the “Projectile” GameObject when it hits the switch.

I suggest you to change the “Bridge2” type from “AnimationClip” to “GameObject” (and point here the gameObject that will be animated), and change the line from:

collision.animation.Play ("Bridge2");

to:

Bridge2.animation.Play ();