내 게임에는 총알이 분사되는 총이 있습니다. 총알과의 충돌로 GameObject를 파괴하려고합니다. 총알은 하나의 gameObject (Capsule)을 기반으로합니다. 지금까지이 두 스크립트를 시도했다 :총알로 총을 맞았을 때 오브젝트가 파괴되지 않습니다. - UNITY3D C#
using UnityEngine;
using System.Collections;
public class whenshot : MonoBehaviour {
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Bullet")
{
Destroy(col.gameObject);
}
}
}
과 :
using UnityEngine;
using System.Collections;
public class whenshot : MonoBehaviour {
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Bullet")
{
Destroy(this); //the difference between the two is that I changed "col.gameObject" to "this"
}
}
}
나는 물체를 촬영하고 있습니다 만 그 자체를 파괴/사라지고 아닙니다. 이 문제를 어떻게 해결할 수 있습니까?
원래 코드가 맞았던 개체가 아니라 총알을 파괴 한 것처럼 보입니다. –
다음 코드 줄을 함수의 맨 위에 추가하고 다시 시도 할 때 로그에 표시되는 내용을 알려줍니다. Debug.Log ("name :"+ col.gameObject.name);','Debug. 로그 메시지를받지 못하면 Log ("matches :"+ (col.gameObject.name == "Bullet"). ToString()); –
@SCottChamberlain 로그가 콘솔 아래에 있으면 로그 메시지가 표시되지 않습니다. –