OnCollisionEnter 未检测到
OnCollisionEnter not detecting
我试图让游戏在碰撞时进入死亡场景,但不起作用。而且它甚至没有检测到碰撞。
我已将脚本附加到空游戏对象上,该对象具有盒式碰撞器并勾选了触发器,玩家也有刚体。
我不知道哪里出了问题,请帮忙。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Health : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnCollisionEnter(Collision collision)
{
Debug.Log("dead without if statement");
if (collision.gameObject.tag == "Player")
{
Debug.Log("Dead Mate");
SceneManager.LoadScene("DeadScreen");
}
}
}
"I've attached the script to empty game object that has box collider with is trigger ticked and the player does have a Rigidbody too."
如果我知道你更正了你在盒子对撞机上启用了触发器,如果是的话你必须实施
void OnTriggerEnter(Collider col)
{
}
不是
public void OnCollisionEnter(Collision collision)
{
}
我试图让游戏在碰撞时进入死亡场景,但不起作用。而且它甚至没有检测到碰撞。
我已将脚本附加到空游戏对象上,该对象具有盒式碰撞器并勾选了触发器,玩家也有刚体。
我不知道哪里出了问题,请帮忙。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Health : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnCollisionEnter(Collision collision)
{
Debug.Log("dead without if statement");
if (collision.gameObject.tag == "Player")
{
Debug.Log("Dead Mate");
SceneManager.LoadScene("DeadScreen");
}
}
}
"I've attached the script to empty game object that has box collider with is trigger ticked and the player does have a Rigidbody too." 如果我知道你更正了你在盒子对撞机上启用了触发器,如果是的话你必须实施
void OnTriggerEnter(Collider col)
{
}
不是
public void OnCollisionEnter(Collision collision)
{
}