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 /
This question was closed Aug 16, 2017 at 07:32 AM by Tech-Nerdz for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Tech-Nerdz · Aug 15, 2017 at 10:24 AM · javascriptif statementinteger

If statement not working

Hello, I'm having trouble getting my if statements to start.

 if(Wave1 > 0)
     {
         Debug.Log("Check");
     }

Here I want it when Wave1 is set to the value of 1, it will Debug.Log("Check");

 function OnTriggerEnter ()
 {
         SurvivalScript.Wave1 += 1;
 }

This is a different script which will add 1 to the Wave1 value.

I want it so it adds 1 to the value when you enter the trigger, then logs ("Check"). Wave1 is a static int and I'm getting no scripting errors, yet I'm getting nothing in the console.

Please help me, Thanks.

Comment
Add comment · Show 6
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 Ali-hatem · Aug 15, 2017 at 11:32 AM 0
Share

add the Debug.Log("Check") inside the function OnTriggerEnter () first to make sure collision is happening

avatar image Tech-Nerdz Ali-hatem · Aug 15, 2017 at 11:39 AM 0
Share

Yes the collision is happening.

avatar image HenryChinaski Tech-Nerdz · Aug 15, 2017 at 11:54 AM 0
Share

I believe this is correct. Error should be somewhere else. $$anonymous$$aybe show your variable declarations.

Show more comments

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by ProgrammerJosh · Aug 16, 2017 at 07:03 AM

Your if statement is in a function called Survival, which is called from the Start method. In Unity, the Start method is only called once when the game object is constructed. I think that your OnTriggerEnter method is being called AFTER the SurvivalScript's Start method has been called, so the if statement never has a chance to respond to the wave increasing

I think what you're trying to do is to poll the state every frame. Try updating your SurvivalScript to this:

  static var Wave1 : int = 0;
  
  function Update()
  {
      Survival();
  }
  
  function Survival ()
  {
      if(Wave1 > 0)
      {
          Debug.Log("Check");
      }
 }

Just be aware that the Update method will be called every frame, so you will get a lot of Debug.Log statements printing.

Good luck friend!

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 Tech-Nerdz · Aug 16, 2017 at 07:31 AM 0
Share

Thanks so much!

avatar image
0

Answer by Rick_Swash · Aug 15, 2017 at 10:22 PM

Check if the OnTriggerEnter function actually gets called

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 Tech-Nerdz · Aug 16, 2017 at 05:59 AM 0
Share

The collision with the trigger is happening, read the replies on the post.

Follow this Question

Answers Answers and Comments

115 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Integer in if statement, scripting help 1 Answer

What is causing my AI script to interpret wrong data? 1 Answer

GUI Counter Based on Animation or RaycastHit 0 Answers

Javascript array questions. 1 Answer

Remove int[] element 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