Question by
issygirl · Feb 18, 2016 at 09:29 AM ·
playererror message
Hello guys this is my enemies script it works very well, l now decided to add UI to it for the scores it started showing errors , am only new to unity pls help
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Differentball : MonoBehaviour {
public GameObject[]spawnPoints;
public GameObject Enemy;
public Text countText;
private int count;
// Use this for initialization
void Start ()
{
spawnPoints = GameObject.FindGameObjectsWithTag("spawn");
count = 0;
SetCountText ();
}
// Update is called once per frame
void Update ()
{
GameObject[] enemies;
enemies = GameObject.FindGameObjectsWithTag ("Enemy");
if (enemies.Length >= 3) {
print ("too many enemies on the dance floor");
}
else
{
InvokeRepeating ("spawnEnemies", 1, 4f);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = " count ; " + count.ToString ();
}
} void spawnEnemies ()
int SpawnPos = Random.Range (0, (spawnPoints.Length - 0));
Instantiate (Enemy, spawnPoints [SpawnPos].transform.position, transform.rotation);
Comment
Answer by issygirl · Feb 18, 2016 at 09:32 AM
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Differentball : MonoBehaviour {
public GameObject[]spawnPoints;
public GameObject Enemy;
public Text countText;
private int count;
// Use this for initialization
void Start ()
{
spawnPoints = GameObject.FindGameObjectsWithTag("spawn");
count = 0;
SetCountText ();
}
// Update is called once per frame
void Update ()
{
GameObject[] enemies;
enemies = GameObject.FindGameObjectsWithTag ("Enemy");
if (enemies.Length >= 3) {
print ("too many enemies on the dance floor");
}
else
{
InvokeRepeating ("spawnEnemies", 1, 4f);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = " count ; " + count.ToString ();
}
} void spawnEnemies ()
int SpawnPos = Random.Range (0, (spawnPoints.Length - 0));
Instantiate (Enemy, spawnPoints [SpawnPos].transform.position, transform.rotation);
CancelInvoke ();
}