How do I make a first-person controller activate a trigger?
I'm really new to Unity, and am trying to create a game a bit like Berband. In the process of creating the automatic doors for the lifts I found that the first-person controller (which is what I'm using for the player) doesn't activate the trigger zone that executes this script:
using UnityEngine;
using System.Collections;
public class Doors : MonoBehaviour {
Animator animator;
bool doorOpen;
void Start()
{
doorOpen = false;
animator = GetComponent<Animator>();
}
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "Player")
{
doorOpen = true;
DoorControl ("Open");
}
}
void OnTriggerExit(Collider col)
{
if(doorOpen)
{
doorOpen = false;
DoorControl ("Close");
}
}
void DoorControl(string direction)
{
animator.SetTrigger(direction);
}
}
EDIT I've figured out what the problem is in the script and it's the gameObject part, what I need now is the name for the first person controller in the script. Any help would be much appreciated.
You have set the controller game object's tag to "Player", correct?
The tricky part is the fact that the script is scanning for a gameObject, but the First Person controller is a prefab. That's why I need to know how to make it scan for a prefab.
A prefab is a gameObject. Just remember that this object has to have the trigger and animators set, and that the controller needs to have some form of physical presence (collider, rigidbody, etc.)
The controller does have a rigidbody set.
An idea that I had was to create a sphere around the controller that would activate the trigger zones. Does the sphere have to have a collider on it? The only reason I'm asking is because it might interfere with the gameplay. (The sphere has a player tag)
Your answer
Follow this Question
Related Questions
Game does not start in Xiaomi Redmi 4A 0 Answers
My Android game is lagging.. 0 Answers
Animation Scripting Issue,Walking Animation Script Not Working 0 Answers
Sprite looks different in game than in editor 0 Answers
UNITY REMOTE 5 WORKS IN ANDROID 9.0??? 0 Answers