OnTriggerEnter 无法正常工作
OnTriggerEnter not working properly
在我制作的游戏中,为了调用死状态,我使用 box collider
来跟踪玩家是否进入特定区域,但问题是它仅在以下情况下跟踪它我正在按键盘上的任何 a,s,d
或 w
键。
这是代码。
第 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;
}
}
}
为gameobject添加rigidbody组件,设置rigidbody组件属性kinematic=false.
在我制作的游戏中,为了调用死状态,我使用 box collider
来跟踪玩家是否进入特定区域,但问题是它仅在以下情况下跟踪它我正在按键盘上的任何 a,s,d
或 w
键。
这是代码。
第 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;
}
}
}
为gameobject添加rigidbody组件,设置rigidbody组件属性kinematic=false.