- Home /
using an objects collider to trigger another objects animation
G'day
I am righting a script in C# for a door that will open when the player approaches it and then close again when the player moves away. the animations all play perfectly fine and the script works however as the door opens the collider moves with it until the player is no longer in the colliders area and the close animation plays until the collider once again touches the player and it will open etc etc... all I am asking for is how I should go about either stopping the collider from moving as the door opens or referencing a collider that is a component of another object, like an empty that will not move as the door does.
thanks in advance.
also if it makes any difference I am using the animator to have it transfer to an idle state and loop either idle open or closed at the end of the open or close animations
using UnityEngine;
using System.Collections;
public class door_controll : MonoBehaviour
{
public Animator anim;
void Start()
{
anim = GetComponent<Animator>();
}
void OnTriggerEnter()
{
anim.Play("open", -1, 0f);
}
void OnTriggerExit()
{
anim.Play("close", -1, 0f);
}
}
Your answer
Follow this Question
Related Questions
setting a bool on another object's animator by player's raycast 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
C# HUD axis button display 0 Answers