Hi guys!
I’m new to unity and csharp, i have the following code which generates enemies and destroy them, however i get this error:
The object of type 'GameObject' has been destroyed but you are still trying to access it.
Here is my enemy generator code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemyGenerator : MonoBehaviour
{
public GameObject original_enemy;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
DecideIfEnemy();
}
private void DecideIfEnemy()
{
float random = Random.Range(0.0f, 100.0f);
if (random < 1.0f)
{
GameObject.Instantiate(original_enemy, transform.position, transform.rotation);
}
}
}
and here is my enemy code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class enemy1 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(new Vector3(-0.005f, 0.0f));
}
}
I don’t know what to do, i already tried to solve by myself but i can’t find or see the issue.. any idea?
Thank you! <3