数据类型,link 游戏检查器中的对象
Data Types, link object in game inspector
所以,我想在 Unity 检查器中添加一个对象,这样当“违规者”与 gameObject 发生碰撞时,它就会被摧毁。但是,我忘记了“public 数据类型”。
如果您在代码中发现任何问题,也请告诉我。
public int offender;
private void OnCollisionEnter(UnityEngine.Collision collision)
{
if(collision.collider.tag == "Bolt" || collision.collider == offender)
{
Destroy(gameObject);
}
}
如果“offender”是 GameObject,您的变量必须是 GameObject 类型:
public GameObject offender;
private void OnCollisionEnter(UnityEngine.Collision collision)
{
if(collision.collider.tag == "Bolt" || collision.gameObject == offender)
{
Destroy(gameObject);
}
}
所以,我想在 Unity 检查器中添加一个对象,这样当“违规者”与 gameObject 发生碰撞时,它就会被摧毁。但是,我忘记了“public 数据类型”。
如果您在代码中发现任何问题,也请告诉我。
public int offender;
private void OnCollisionEnter(UnityEngine.Collision collision)
{
if(collision.collider.tag == "Bolt" || collision.collider == offender)
{
Destroy(gameObject);
}
}
如果“offender”是 GameObject,您的变量必须是 GameObject 类型:
public GameObject offender;
private void OnCollisionEnter(UnityEngine.Collision collision)
{
if(collision.collider.tag == "Bolt" || collision.gameObject == offender)
{
Destroy(gameObject);
}
}