0
votes

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 called 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.98f);

        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 OnTriggerStay(Collider other)
    {
        Debug.Log(other.tag);
        if (other.gameObject.tag == "Generador")
            GenerateManager.Instante.DoGenerate = true;
        if (other.gameObject.tag == "Muerte")
        {
            Alive = false;
            Death = true;
        }
    }
}
1
OnTriggerEnter or OnTriggerStay ? - Dinal24

1 Answers

1
votes

Add rigidbody component to gameobject,set rigidbody component attribute kinematic=false.