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 /
avatar image
0
Question by _Toxic · Oct 15, 2015 at 11:01 AM · unity 5instantiate2d-platformerupdate functioncurrency

Instantiating an object only once within Update()

This is what i have so far. if i collect some coins they get stored in the GameBrain script. when i make it to a chest i can store the coins in there and that value gets stored in the GameBrain at coinsStored. i have that all working fine i even had the object instantiating after i stored 10 coins. its when i tried to make it happen only once by adding the if(UnlockComplete = false)statement. (i know there is nested loops i have fixed that but still no change.) that i have issues with it not spawning at all.

public class UnlockFloor : MonoBehaviour {

 public GameObject obj;                 //passed from unity
 public float UnlockAmout = 10f;         //usually set by unity 10 is default
 private bool UnlockComplete = false;    //Stops a MillionBajillion "Things" from spawning


 void OnDrawGizmosSelected() {            //A Gizmo so i can see the "Things" spawner
     Gizmos.color = new Color(1, 0, 0, 0.5F);
     Gizmos.DrawCube(transform.position, new Vector3(1, 1, 1));
 }
 

 void Update () {
     if(GameBrain.coinsStored > UnlockAmout) {
         if(UnlockComplete = false){
             UnlockTheThing();
             UnlockComplete = true;
         }
     } 
 }
 //Unlocks the "Thing" in question set by obj
 void UnlockTheThing(){
     Instantiate(obj, transform.position, Quaternion.identity);
 }

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by _Toxic · Oct 15, 2015 at 08:44 AM

For googlers coming here in the future 1st of all greetings from the past. 2nd here is what went wrong

if(UnlockComplete = false){

should read

if(UnlockComplete == false){

= needs to be ==

Comment
Add comment · Show 1 · Share
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 DDeathlonger · May 18, 2018 at 05:54 AM 0
Share

hahahahaha hello from the future! this was WAY different than I was looking for but I liked your greeting.. so ya know. XD

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

Need suggestion or advice on my 2d platformer 0 Answers

instantiate spawning meany objects in multiplayer 0 Answers

Is there anyway to delete clones that are local variables? 1 Answer

How to instantiate platforms like Doodle Jump game ? 1 Answer

2D game Unity5 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