using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class powerUpManager : MonoBehaviour {
public GameObject[] powerUpPrefab;
public Vector3 center;
public Vector3 size;
void Start()
{
InvokeRepeating("SpawnFood",5f,5f);
}
void SpawnFood()
{
Vector3 pos =center+ new Vector3(Random.Range(-size.x/2,size.x/2),Random.Range(-size.y/2,size.y/2),Random.Range(-size.z/2,size.z/2));
Instantiate (Random.Range(0,powerUpPrefab), pos, Quaternion.identity);
}
void OnDrawGizmosSelected()
{
Gizmos.color = new Color (0, 1, 0, 0.5f);
Gizmos.DrawCube (center, size);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class powerUpManager : MonoBehaviour {
public GameObject[] powerUpPrefab;
public Vector3 center;
public Vector3 size;
void Start()
{
InvokeRepeating("SpawnFood",0.5f,0.5f);
}
void SpawnFood()
{
Vector3 pos =center+ new Vector3(Random.Range(-size.x/2,size.x/2),Random.Range(-size.y/2,size.y/2),Random.Range(-size.z/2,size.z/2));
//Modify the line below as follows, and everything will work fine:
Instantiate (powerUpPrefab[Random.Range(0,powerUpPrefab.Length)], pos, Quaternion.identity);
}
void OnDrawGizmosSelected()
{
Gizmos.color = new Color (0, 1, 0, 0.5f);
Gizmos.DrawCube (center, size);
}
}