Question by
Zandlie · Jun 15, 2016 at 06:22 AM ·
instantiateupdatespawn
Instantiate prefab
Hello all! what im trying to do is instantiate a prefab when the player score is equal to a public int. when the score hits the in value the prefab spawns but 20-40 times. i have a bool lock out for it. so when the game starts its false but when the score is at the in it turns true, then it spawns. what i need to happen is it to spawn once. Then in another code the int is changed so then the bool should turn false but it doesnt. any help would be amazing :)
this is the instantiate code
using UnityEngine;
using System.Collections;
public class BossController : MonoBehaviour {
public GameObject enemy;
public Vector3 spawnValues;
public int ScoreSpwn;
public static BossController bosscontroller;
public bool Spawned;
void Start(){
bosscontroller = this;
Spawned = false;
}
void Update(){
if (ScoreManager.score >= ScoreSpwn && !Spawned) {
SpawnBoss ();
Spawned = true;
}
}
public void SpawnBoss(){
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (enemy, spawnPosition, spawnRotation);
}
}
This is the Code thats changing the int value
using UnityEngine;
using System.Collections;
public class XinMissions : MonoBehaviour {
public GameObject bossStop;
public GameObject StartUI;
public GameObject Part2UI;
public Transform UIgo;
void Start(){
bossStop.SetActive (false);
StartUI.SetActive (true);
Part2UI.SetActive (false);
}
void Update(){
if (ScoreManager.score >= 25) {
GameController.gamecontroller.astroidCount = 10;
EnemyController.enemycontroller.enemyCount = 1;
}
if (ScoreManager.score >= 50) {
GameController.gamecontroller.astroidCount = 3;
EnemyController.enemycontroller.enemyCount = 2;
}
if (ScoreManager.score >= 100) {
GameController.gamecontroller.astroidCount = 1;
EnemyController.enemycontroller.enemyCount = 3;
EnemyController.enemycontroller.waveWait = 0.5f;
}
if (ScoreManager.score >= 150) {
GameController.gamecontroller.astroidCount = 1;
EnemyController.enemycontroller.enemyCount = 4;
EnemyController.enemycontroller.waveWait = 0.25f;
}
if (ScoreManager.score >= 250) {
GameController.gamecontroller.astroidCount = 0;
EnemyController.enemycontroller.enemyCount = 0;
bossStop.SetActive (true);
}
if (ScoreManager.score >= 1250) {
Part2UI.SetActive (true);
bossStop.SetActive (false);
}
if (ScoreManager.score >= 1350) {
GameController.gamecontroller.astroidCount= 5;
EnemyController.enemycontroller.enemyCount = 3;
}
if (ScoreManager.score >= 1450) {
GameController.gamecontroller.astroidCount = 2;
EnemyController.enemycontroller.enemyCount = 0;
bossStop.SetActive (true);
}
if (ScoreManager.score >= 1550) {
GameController.gamecontroller.astroidCount = 0;
EnemyController.enemycontroller.enemyCount = 0;
bossStop.SetActive (true);
}
}
public void Part2(){
ScoreManager.score += 100;
BossController.bosscontroller.ScoreSpwn = 1400;
Player.player.CurHealth = Player.player.MaxHealth;
Part2UI.transform.position = UIgo.transform.position;
}
public void Begin(){
StartUI.SetActive (false);
}
}
Comment
wait so what is not working? the spawning part or the score management?
And you really should clean that horrible if forest ! like creating a struct array or something