Trigger an Object an play Animations

Hi,

Im working on a FPS at the moment (based on the tutorial) and got a problem with animations.
It should work this way:
If you look at an crank and press “e” in front of it an animation should start.

I created the object and the animations in C4D.
Imported them to Unity, import-options for the animations as follows:
Generation: Store in Root
Anim. Compression: keyframe Reduction
Anim. Wrap method: default
Split Anim: yes

Animations:
idle 0 0 default
down 0 10 default

After that i placed the objects in my game and added a Tag named “Konsole”.
Then i created a javascript file, added this to the object aswell.

function Update () {
	if(Input.GetKeyDown("E")){
		var object = gameObject.FindWithTag("Konsole");
		object.animation.Play("down");
	}

}

If I start the game and try to activate the object nothing happens.
Allready tried to switch “e” for a right-Mouseclick, but couldn’t find the correct name for that.

Would be great if someone could help me.

it’s GameObject, not gameObject.

I believe you have to use “e”

Fixed it, now it works :smile:

Here’s the complete code, I’m sure that there’s a better way but it works.

//Object can only be used once
var hebelLagerhalleUsed : boolean = false;
//that's the player 
var target : Transform;
//distance you can activate the object from
var reichweite = 5.0;

function Update () {
	if((Input.GetKeyDown("e") )  (hebelLagerhalleUsed == false)  (PlayerInHebelReichweite())){
		hebelLagerhalleUsed = true;
		var hebel = GameObject.FindWithTag("KonsoleLagerhalle");
		hebel.animation.Play("down");
	}

}

//checks if player is in distance to activate the object
function PlayerInHebelReichweite () : boolean{
	if (Vector3.Distance(transform.position, target.position) > reichweite){
		return false;
	}else{
		return true;
	}

}

Thread can be closed.