How can i make it spawn a object when the bool state is true? i have it set up but it is not working why? this is C# script.
using UnityEngine;
using System.Collections;
public class cointopon : MonoBehaviour
{
public Transform[] spawnPoints;
public GameObject[] enemyPrefabs;
public float amountEnemies = 20; // Total number of enemies to spawn.
public float yieldTimeMin = 0;
public float yieldTimeMax = 5; // Don't exceed this amount of time between spawning enemies randomly.
public int i;
public bool state;
void Update() {
yieldTimeMin = PlayMakerGlobals.Instance.Variables.GetFsmFloat("coinboolmin").Value;
yieldTimeMax = PlayMakerGlobals.Instance.Variables.GetFsmFloat("coinboolmax").Value;
amountEnemies = PlayMakerGlobals.Instance.Variables.GetFsmFloat("coinboolamount").Value;
state= PlayMakerGlobals.Instance.Variables.GetFsmBool("coinbool").Value;
}
public IEnumerator Spawnblock()
{
if (state == true) {
for (i=0; i<amountEnemies; i++){
var randNum = Random.Range(0, spawnPoints.Length);
yield return new WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax)); // How long to wait before another enemy is instantiated.
var obj = enemyPrefabs[Random.Range(0, enemyPrefabs.Length)]; // Randomize the different enemies to instantiate.
var pos = spawnPoints[randNum];
Instantiate(obj, pos.position, pos.rotation);
}
}
}
}
How can i solve the IndexOutOfRange error?
– Chris12345I have a counter that is what i is it counts the spawned objects but it shows 0 and i know the counter works.
– Chris12345public IEnumerator Spawnblock() would this be running ever frame if i am using send message?
– Chris12345I also know that the bool is true and then goes false when it is to.
– Chris12345Not working it is not spawning when bool is true?
– Chris12345