ANIMATION TRIGGER DOESN'T PLAY
Hi i try to play an animation trigger ( it's just a door that moving up ) but when i press play i have no error information in my console and in my game the collider doesn't work my FPSController goes through the door ! this is the script i used
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoorOpen : MonoBehaviour {
Animation Animation;
void Start()
{
Animation = GetComponent<Animation>();
}
void OnTriggerEnter(Collider other)
{
if (GetComponent<Collider>().name == "FPSController")
{
Animation.Play("OpenDoor");
}
}
}
Answer by yummy81 · Feb 09, 2018 at 06:49 AM
The reference to the object you collided with (in your case "FPSController") is held in the "other" variable and this is the reference you need. But what you are trying to do is to get the reference to the collider which is attached to the gameobject to which your script is also attached, which is pointless. The problem lies here:
if (GetComponent<Collider>().name == "FPSController")
just change the above line to this:
if (other.name == "FPSController")
Your answer
Follow this Question
Related Questions
How to have a game object register its OnTriggerEnter function? 1 Answer
I want to trigger an animation upon collision with a 2D obstacle in my infinite runner game.Help me. 0 Answers
How to detect collision of two moving characters? 1 Answer
Help with a door slam trap 0 Answers
On collision enter next scene 2 Answers