- Home /
Question by
MatrixGfx · Jul 19, 2015 at 07:15 PM ·
javascriptanimatortriggerunity5
How can I properly trigger the trigger of animator in js script?
Hello, me and my friend are creating a game and currently I'm trying to trigger a player animation whenever it is hit by an object. We have the animation, I've created a trigger parameter in animator all I need to do now is actually trigger that trigger from our script which detects collision. Here's the script but it is not working for whatever reason, keeps giving me error "an instance of type 'UnityEngine.Animator' is required to access non static member 'SetTrigger'". The trigger condition in unity is called "hit".
#pragma strict
public var isTrigger: Collision2D;
public var score = 0;
function Start () {
var animator: Animator;
animator = GetComponent.<Animator>();
}
function OnCollisionEnter2D (colInfo : Collision2D) {
if (colInfo.collider.tag == "Sphere") {
Debug.Log("It's Working");
Destroy (colInfo.gameObject);
score++;
Animator.SetTrigger("hit");
}
}
We are fairly new to unity and programming, also we often try to adapt C# tutorials to JS and vice versa, which actually is the case here. ^
So perhaps someone could give me an idea what is wrong here? Thanks in advance
Comment
Your answer
