【发布时间】:2019-11-25 06:43:06
【问题描述】:
我试图让游戏在被碰撞时进入死亡场景不起作用。它甚至没有检测到碰撞。
我已将脚本附加到空的游戏对象上,该游戏对象的盒子碰撞器已被触发,并且玩家也确实有刚体。
我不确定是什么问题,请帮忙。
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");
}
}
}
【问题讨论】:
-
可能“健康”类没有碰撞器。您的 Player 类可能会发生碰撞,您应该使用 Player 类而不是 Health 类来检测碰撞。
-
尝试在玩家游戏对象中放置一个对撞机,您是否将标签“玩家”放入玩家游戏对象中?我认为这是您提供的信息可能遇到的 2 个错误。
-
我同意 YouneS 的观点。您应该将您的关注点分开:检测碰撞和处理碰撞
-
对于碰撞,检查Unity's Colliders page 并匹配您的两个对象的属性以确定是否会检测到碰撞。