- Home /
Problem with OnTriggerEnter
Please if someone could help me with this, i tried everything and nothing worked.
In the game I'm making in order to call a dead state I'm using a box collider to track if the player enters in a particular zone, but the problem is that it only tracks it if I'm pressing any of the a,s,d or w keys in the keyboard.
This is the code.
The OnTriggerEnter is call in line 48.
using UnityEngine;
using System.Collections;
public class PlayerManager : MonoBehaviour
{
public bool Death = false;
public bool Alive = false;
public bool Muerto;
public GameObject Generador;
public GameObject StartButton;
public CharacterMotor Motor;
public static PlayerManager Instanse;
// Use this for initialization
void Start()
{
Instanse = this;
}
// Update is called once per frame
void Update()
{
if (gameObject.transform.position.y <= -3.5f)
Death = true;
if (!Alive)
Generador.transform.position = new Vector3(0, -0.57f, -4.12f);
if (Death)
{
Generador.transform.position = new Vector3(0, -0.57f, -4.12f);
GenerateManager.Instante.BeforeObject = GenerateManager.Instante.Spawn;
Motor.canControl = false;
StartButton.SetActive(true);
CameraMovement.Instanse.CanMoveCamera = false;
gameObject.transform.position = new Vector3(0.46f, 1.102971f, -6);
Camera.main.transform.position = new Vector3(-0.07402526f, 12.0031f, -1.937099f);
foreach (GameObject gm in GenerateManager.Instante.BloquesGenerados)
{
Destroy(gm);
}
GenerateManager.Instante.BloquesGenerados.Clear();
Death = false;
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Generador")
GenerateManager.Instante.DoGenerate = true;
if (other.gameObject.tag == "Muerte")
{
Alive = false;
Death = true;
}
}
}
If someone can help me fix this i will be very grateful.
What do you mean by only pressing a,s,d or w? if you use the arrows it doesn´t trigger?
If you want it to check if the player entered and is still there use OnTriggerStay.
Pretty sure they mean when the the characters moving. Try doing OnTriggerEnter on both the player and the object that has the trigger. See if when it doesn't trigger on one it triggers on the other.
Where is the script attached? It should be on the player!
Your answer
Follow this Question
Related Questions
Ontriggerenter not working 1 Answer
Where is this (-1) coming from in my change level script? 1 Answer
how to fix third person 1 Answer
NullReferenceException Error 2 Answers