Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

transform is destroyed (ERROR)... and I want the game to complete

$
0
0
I followed a tutorial to make the enemy follow and identify the player's position but when the player die it give the following error: 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. I don't know how to fix thanks for your time there are 2 scripts one for enemy and one for projectile the enemy script:::: public class enemyCir : MonoBehaviour { //عام public ParticleSystem enemyDeathEffect; private Transform circle; //خاص public GameObject projectile; private void Start() { //عام circle = GameObject.FindWithTag("circle").transform; } private void Update() { //عام if (Vector2.Distance(transform.position, circle.position) < stoppingDistance){ transform.position = Vector2.MoveTowards(transform.position, circle.position, speed * Time.deltaTime); } //عام private void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.GetComponent()) { Destroy(gameObject); Instantiate(enemyDeathEffect, transform.position, Quaternion.identity); } } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>