void Awake() { if (instance != null) { Debug.LogError("More than one EnemyInfoPanel in scene !"); return; } instance = this; }
private IEnumerator SpawnInfoPanel() { if (infoPanelPrefab != null) { yield return(new WaitForSeconds(infoSpawnDelay)); EnemyInfoPanel infoPanel = Instantiate(infoPanelPrefab, transform.position, Quaternion.identity) as EnemyInfoPanel; infoPanel.transform.SetParent(infoPanelCanvas.transform, false); infoPanel.transform.position = transform.position + infoPanelOffset; infoPanel.SetCurrentUnit(enemy); } }
public void Start() { if (instance == null) { //...set this one to be it... instance = this; } //...otherwise... else if (instance != this) { //...destroy this one because it is a duplicate. Destroy(gameObject); } }