Hey all,
I’ve been working on this script for a while, I’ve got a lot of help from other peoples questions.
I have it currently working for the most part. I just cant seem to get the first spawn to be at random locations.
Here’s the code
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class FoodSpawner : MonoBehaviour {
public float range;
public GameObject food;
public List<GameObject> spawnList;
// Use this for initialization
void Start ()
{
spawnList = new List<GameObject>();
InvokeRepeating("FindFood", 1, 1);//(methodname, time, repeat time)
//Populate for the first time
for (int i = 0; i < 10; i++)
{
spawnList.Add(Instantiate(food) as GameObject); //spawnList.Add(new GameObject(food.ToString())); //Time.timeSinceLevelLoad.ToString()));
}
}
void FindFood()
{
Vector3 randomPos = Random.insideUnitSphere * range;
randomPos.z = 0;
for (int i = 0; i < spawnList.Count; i++)
{
if(!spawnList*)*
-
{*
_ spawnList = Instantiate(food, (transform.position + randomPos), Quaternion.identity) as GameObject; //GameObject.CreatePrimitive(PrimitiveType.Cube);_
* }*
* }*
* }*
}
I’m still somewhat new at this stuff. So go easy on me
Thanks