[英]Why is my “Character” still moving through the gameObject instead of the game object destroying
我似乎無法與Character
發生碰撞以導致游戲 object 自行破壞。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CollectItem: MonoBehaviour
{
void OnCollisionEnter(Collision collision){
if(collision.gameObject.name == "Character"){
Destroy(gameObject);
}
}
}
可能有多種原因:
附帶說明一下,在比較字符串時,您應該始終使用 Equals 方法,即 collision.gameObject.name.Equals("Character")。 不過,這不是你的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.