Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 stay.metal · Feb 06, 2015 at 02:33 AM · scorespawningif

If score spawn objects

If someone scores i want an object to spawn if i use += 1; it says int cant convert into bool if i use <= 1; it just keeps spawning

 using System.Collections;
 
 public class Ifmove : MonoBehaviour {
 
     public GameObject Row;
 
     
     // Update is called once per frame
     void Update () {
         if(PointScore.pointScore += 1){
             Instantiate(Row, transform.position, Quaternion.identity);
         }
     }
 }

please help thank you

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
0

Answer by Deathdefy · Feb 10, 2015 at 12:46 AM

This should solve your issue.

void Update () {

     //Assuming PointScore.pointScore is 0, this will fire off once and never again after that
     PointScore.pointScore++;

     if(PointScore.pointScore <= 1){
         Instantiate(Row, transform.position, Quaternion.identity);
     }
 }



The issue you experienced was the fact that you were attempting to check an integer as a bool as you are using `if(PointScore.pointScore += 1) which is not a valid expression. So with the solution I provided pointscore is now only going to resolve as true if it is less than or equal to 1

Comment
Add comment · Show 3 · 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 stay.metal · Feb 12, 2015 at 02:37 AM 0
Share

I tried your method but my prefab just keeps spawning, it doesn't stop

avatar image Deathdefy · Feb 12, 2015 at 09:52 PM 0
Share

Can you post all of the code you are currently using for me? Unless you are editing pointScore's value somewhere else this should only run 1 time.

avatar image stay.metal · Feb 12, 2015 at 10:41 PM 0
Share

Well i have 3 scripts using the code. First one is just the score with a simple gui using UnityEngine; using System.Collections;

public class PointScore : $$anonymous$$onoBehaviour { public static int addScore; void Start(){

      PointScore.addScore = 0;
  }
  void OnGUI ()
  {
      GUI.Label (new Rect (10, 10, 100, 20), "Score: " + addScore);
  }

}

The second one is a trigger that just detect my square at a certain position and if you get it correctly you add a score using UnityEngine; using System.Collections;

public class Thetrigger : $$anonymous$$onoBehaviour {

  public bool triggered;
 
  void Update(){
      if (triggered == true) {
          if(Input.Get$$anonymous$$ouseButtonDown(0)){
              PointScore.addScore += 1;
          }
              }
      }
  
  void OnTriggerEnter2D(Collider2D coll){
      if (coll.gameObject.tag == "red"){
          triggered = true;
      }
 
  }
  
  void OnTriggerExit2D(Collider2D coll){
              if (coll.gameObject.tag == "red") {
                      triggered = false;
              }
      }
  }

The Last one is just the spawner that moves up after it spawns my prefab

using UnityEngine; using System.Collections;

public class Spawn$$anonymous$$over : $$anonymous$$onoBehaviour {

  public GameObject daprefab;
 
  // Update is called once per frame
  void Update () {
      if(PointScore.addScore <= 1){
          Instantiate(daprefab,transform.position,Quaternion.identity);
          transform.Translate(Vector3.up * 6);
  }

} }

Im trying to make a simple stacker game, for my own solo project to get to know unity.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

if statement not working 1 Answer

Call function every time the player gets 5 points 1 Answer

If statement not catching certain parameters? 2 Answers

Having camera attack upon spawning player? 1 Answer

ai spawning please help 0 Answers


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