- Home /
The object of type 'Transform' has been destroyed but you are still trying to access it.
using UnityEngine; using System.Collections; using UnityStandardAssets.ImageEffects;
public class GameMaster : MonoBehaviour {
public static GameMaster gm;
void Awake () {
if (gm == null) {
gm = GameObject.FindGameObjectWithTag ("GM").GetComponent<GameMaster>();
}
}
public Transform playerPrefab;
public Transform spawnPoint;
public float spawnDelay = 2;
public Transform spawnPrefab;
public CameraShake cameraShake;
void Start()
{
if (cameraShake == null)
{
Debug.LogError("No camera shake referenced in GameMaster");
}
}
public IEnumerator _RespawnPlayer () {
GetComponent<AudioSource>().Play ();
yield return new WaitForSeconds (spawnDelay);
Instantiate (playerPrefab, spawnPoint.position, spawnPoint.rotation);
GameObject clone = Instantiate (spawnPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject;
Destroy (clone, 3f);
}
public static void KillPlayer (Player player) {
Destroy (player.gameObject);
gm.StartCoroutine(gm._RespawnPlayer());
}
public static void KillEnemy (Enemy enemy) {
gm._KillEnemy(enemy);
}
public void _KillEnemy(Enemy _enemy)
{
GameObject _clone = Instantiate(_enemy.deathParticles, _enemy.transform.position, Quaternion.identity) as GameObject;
Destroy(_clone, 5f);
cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength);
Destroy(_enemy.gameObject);
}
}
strong text MY QUESTION : How to Fix? ERROR : MissingReferenceException: The object of type 'Transform' 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. UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineObjectBindings.gen.cs:63) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:80) GameMaster+c__Iterator10.MoveNext () (at Assets/Scripts/GameMaster.cs:34)
please format ALL of your code so that the error messages match the correct line numbers of the posted code. without that, it's going to be difficult to help you.
Your answer
Follow this Question
Related Questions
script trying to access a null gameobject's collider... can't fix 2 Answers
How to only delete one of two collided objects? 1 Answer
Collision between 2 prefabs. 0 Answers
Collision with a coin 0 Answers