using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pickup : MonoBehaviour
{
public GameObject _Pickaxe;
// Start is called before the first frame update
void Start()
{
_Pickaxe = GameObject.Find("Pickaxe");
}
// Update is called once per frame
void Update()
{
}
void DestroyGameObject()
{
Destroy(gameObject);
}
private void OnTriggerEnter(Collider collision)
{
Debug.Log("Collided with +" + collision.gameObject.name);
if(collision.gameObject.name == "Pickaxe" );
{
Debug.Log("Touched pick");
}
}
}
在我的剧本中,它记录了角色接触到的任何东西。在我的场景中,我有一个物体被放置在距离玩家太空舱产生地大约10米的地方,不知何故,它在你移动之前就与它相撞了。
您的代码有一个错误。它记录每次碰撞的"Touched pick"
。要修复它,您应该删除此行if(collision.gameObject.name == "Pickaxe" );
中的分号