我想將我的球員破壞怪物創建相同的遊戲物體和我第一次摧毀一個怪物,我有以下錯誤:如何銷燬,團結
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
我怎樣才能使它複製本身作爲一個新的遊戲對象?
這是我的腳本:
using System.Collections.Generic;
using UnityEngine;
public class TimeMap: MonoBehaviour {
public GameObject selectedUnit;
public GameObject selectedMonster;
public TileType[] tileTypes;
try{
if(selectedMonster.GetComponent<Monster>().tileX == selectedUnit.GetComponent<Unit>().tileX && selectedMonster.getComponent<Monsters>().tileY == selectedUnit..GetComponent<Unit>())
Destroy(selectedMonster);
}
public void SpawnMon() {
if(counter % 5 == 0){
Debug.Log(" counter % 5 == 0");
Instantiate(selectedMonster.GetComponent<Monsters>().Monster, new Vector3(Random.Range(1,8), Random.Range(1,8), -1), Quaternion.identity);
}
}
}
所以我嘗試創建相同的對象或它的每移動5的克隆,但我有錯誤,同時這樣做。
請不要張貼您的代碼的屏幕截圖。改爲發佈代碼。 – Programmer