- Home /
The question is answered, right answer was accepted
Help: script that worked don't work with Unity 3.5
Hello everyone,
I need help with a spawnscript I made that worked earlie,r but with the recent updates on Unity, it does not seems to work.
Here's the script:
using UnityEngine; using System.Collections;
public class SpawnScript : MonoBehaviour { public int AmountEnemyInWave; public float SpawnCountdown = 1.0f; public GameObject[] spawnPoints; public GameObject[] enemy;
private float SpawnTimer;
private int CurrentEnemyNumber = 0;
private bool hasFinished = false;
void Start()
{
SpawnTimer = 0.0f;
}
void SpawnEnemy()
{
if(!hasFinished)
{
SpawnTimer += Time.deltaTime;
// Debug.Log("SpawnTimer value " + SpawnTimer);
// Debug.Log("SpawnCountdown value " + SpawnCountdown);
// Debug.Log("SpawnTimer value >= SpawnCountdown value : " + (SpawnTimer >= SpawnCountdown));
if(SpawnTimer >= SpawnCountdown)
{
// Debug.Log ("Hi darling");
Debug.Log(enemy[0]);
Debug.Log(spawnPoints[0]);
Instantiate(enemy[0], (spawnPoints[0].transform.position), (spawnPoints[0].transform.rotation));
CurrentEnemyNumber += 1;
SpawnTimer = 0.0f;
}
}
}
void Update()
{
SpawnEnemy();
if(CurrentEnemyNumber >= AmountEnemyInWave)
{
// Debug.Log("CurrentEnemyNumber >= AmountEnemyInWave : " + (CurrentEnemyNumber >= AmountEnemyInWave));
hasFinished = true;
}
}
}
Notice that all the Debug.Log are in comments, but I can attest that they work. I've seen them all print their message at the console screen.
In the enemy array, I put a prefab of my enemy. It's important to take this into account because the main problem is that Unity seems to detect the spawn thing (since the debug.log // Debug.Log("CurrentEnemyNumber >= AmountEnemyInWave : " + (CurrentEnemyNumber >= AmountEnemyInWave)); does show in console) But no physical enemy appears.
Any clues, someone? This is a major issue for me. Thanks a lot!
Problem has been solved, it was external to the script. Thank you for ignoring this question. :)
Follow this Question
Related Questions
Spawn a prefab 1 Answer
Setting Position of Spawned Prefab 2 Answers
Check if with a spawned gameobject 1 Answer
Randomly spawn the same object with different properties consistently. 2 Answers