Unity C#-同时具有OnTiggerExit和OnTiggerEnter时,只调用OnTiggerExit
好吧,我看不出我的问题在哪里。我用OnTiggerEnter作为移动平台。它有刚体组件,在平台和播放器上,框碰撞器都设置为isTrigger,但由于某种原因,当播放器触发我的平台时,只有OnTriggerExit被调用。我的玩家被标记为unity中的玩家。。。我不知道该怎么办 代码: 所有检查员Unity C#-同时具有OnTiggerExit和OnTiggerEnter时,只调用OnTiggerExit,c#,unity3d,game-development,C#,Unity3d,Game Development,好吧,我看不出我的问题在哪里。我用OnTiggerEnter作为移动平台。它有刚体组件,在平台和播放器上,框碰撞器都设置为isTrigger,但由于某种原因,当播放器触发我的平台时,只有OnTriggerExit被调用。我的玩家被标记为unity中的玩家。。。我不知道该怎么办 代码: 所有检查员 BoxCollider在Moving_Platform GameObject中添加了两次,一次为触发启用值,另一次为非触发启用值。为什么会这样? 为了更好地进行测试,您可以在if语句之外添加Deb
BoxCollider在Moving_Platform GameObject中添加了两次,一次为触发启用值,另一次为非触发启用值。为什么会这样?
为了更好地进行测试,您可以在if语句之外添加Debug.Log(other.name)来查看正在发生的事情。似乎是更新到新版本(2020.x)成功了。 谢谢你的努力
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Moving_Platform : MonoBehaviour
{
[SerializeField]
private float _speed = 1.0f;
[SerializeField]
private Transform _A, _B;
private bool _direction = false;
void FixedUpdate()
{
if(transform.position==_A.position)
{
_direction = false;
}
else if(transform.position== _B.position)
{
_direction = true;
}
if (_direction == false)
{
transform.position = Vector3.MoveTowards(transform.position, _B.position, _speed * Time.deltaTime);
}
if(_direction==true)
{
transform.position = Vector3.MoveTowards(transform.position, _A.position, _speed * Time.deltaTime);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
other.transform.parent = this.transform;
}
}
private void OnTriggerExit(Collider other)
{
Debug.Log("OMFG");
if (other.tag == "Player")
{
Debug.Log("But why!");
other.transform.parent = null;
}
}
}