using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SceneController : MonoBehaviour {
[SerializeField] private GameObject enemyPrefab;
private GameObject _enemy;
void Update () {
if (_enemy == null) {
_enemy = Instantiate (enemyPrefab) as GameObject;
_enemy.transform.position = new Vector3 (0,1,0);
float angle = Random.Range (0, 360);
_enemy.transform.Rotate (0, angle, 0);
}
}
}
It’s a code from a book Unity in Action. This code instantiate enemy prefab every time I destroy previous one. One thing I can’t undestand how this line of code"private GameObject _enemy;" keeps track on GameObj that I just Instantiated. So I have a couple of questions.
- Is it working because I have just one prefab instantiated in the scene?
- How it actualy keeps track on instantiated gameObject without any assingment?
- What can you reccomend to read along with Unity in Action to learn C# better, it’s obvious I have no exp in programming languages before. I currently just google every question I have, so it’s hard to make a strong consistant foundation for C# knowledge.
Thanks for the answers!