本文介绍了OnTriggerEnter 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..在我为了调用死状态而制作的游戏中,我使用 box collider
来跟踪玩家是否进入特定区域,但问题是它只跟踪如果我按下键盘上的任何 a,s,d
或 w
键.
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.
这是代码.
OnTriggerEnter
在第 48 行被调用.
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;
}
}
}
推荐答案
为游戏对象添加刚体组件,设置刚体组件属性 kinematic=false.
Add rigidbody component to gameobject,set rigidbody component attribute kinematic=false.
这篇关于OnTriggerEnter 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论