Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EpiFouloux · Jun 15, 2016 at 07:56 AM 0
Share

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Instantiate only once in Update and be able to use the clone variable in a switch statement(in Update). 1 Answer

Problem with Instantiated clones 1 Answer

How can I make an object clone in the time that I indicate it to appear? 0 Answers

Wont instantiate game object 1 Answer

objects not spawn where they should 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges