OnTriggerEnter无法正常工作

时间:2015-02-04 01:17:48

标签: c# unity3d

在我为了打电话给死亡状态而制作的游戏中,我使用box collider跟踪玩家是否进入特定区域,但问题是它只跟踪如果我按下键盘上的任意a,s,dw键,就可以了。

这是代码。

第48行调用OnTriggerEnter

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 个答案:

答案 0 :(得分:1)

将刚体组件添加到gameobject,设置刚体组件属性kinematic = false。