- Home /
Question by
saaayc · Jun 24, 2016 at 05:02 AM ·
animationcollidersfunctiontriggering animation box collider
Activating an animation upon triggering the collider?
Hi there!
So I'm trying to trigger an animation when I'm inside the collider which will move the chair back upon a mouse click. I'm just quite confused on how to integrate it inside the OnTriggerEnter? Clicking on the mouse still triggers the animation despite being outside the collider. I was wondering if there's a simpler way of integrating the trigger with the collider?
Thanks!
public var chairAnimator: Animator;
public var isChairMoved : boolean = false ;
public var isChairActive : GameObject ;
function Start () {
}
function OnTriggerEnter (other: Collider){
isChairActive.SetActive(true);
}
function OnTriggerExit (other: Collider){
isChairActive.SetActive(false);
}
function Update () {
if (Input.GetMouseButtonDown(0)){
if (isChairMoved == false){
Debug.Log("Mouse Clicked");
chairAnimator.Play("Chair_Moved_Backwards");
}else{
chairAnimator.Play("Chair_Moved_Forwards");
}
isChairMoved = !isChairMoved;
}
}
Comment
Your answer
Follow this Question
Related Questions
animation plays once multiple colliders are placed? 0 Answers
AnimationEvent has no function name specified 2 Answers
How to properly animate a player interacting with an object? 0 Answers
How to properly setup kinematic rigid bodie(s) and colliders in animated human character 0 Answers
Stop a function? 3 Answers