I'm trying to apply a null on an array. the arrays are points where game prefabs are being instantiated. At some point in the game, these spawn points may be destroyed. when this happens, the code is still trying to access that spawn point even though it no longer exists, so i'm trying to make it null. so far i have been unsuccessful. This is the last thing in the game i need to fix. help is appreciated.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class podControl : MonoBehaviour {
public Transform [] spawns;
public float spawnTime = 6f;
public float secondSpawnTime = 3f;
public GameObject podPrefab;
void Start ()
{
InvokeRepeating ("landingPod", spawnTime, secondSpawnTime);
}
void landingPod ()
{
int spawnIndex = Random.Range (0, spawns.Length);
if (spawns != null) {
Instantiate (podPrefab, spawns [spawnIndex].position, spawns [spawnIndex].rotation);
}
}
}
Aucun commentaire:
Enregistrer un commentaire