• 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
Question by Selevan · Jun 20, 2013 at 01:19 PM · movementaispeedcounterturn-based

Do something every each multiple of 1000..

I have a char that add's 750 to the "turncounter" variable every each move, and i wanted to put an npc which would move in a random direction everytime the "turncounter" hits 1000, 2000, 3000, etc.

So for 750 - 1000 it would work like that: player move, npc stays at same position (750 - 1000) player move, npc move (1500 - 1000) player move, npc move (2250 - 2000) player move, npc move (3000 - 3000) player move, npc stays (3750 - 3000)

etc. How to do that ? Preferably JS.

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Stormizin · Jun 20, 2013 at 01:25 PM

Try something like that, actually in C#:

 public int result = 0;
 public int multipler = 0;
 
 
 void Update(){
 //Numbers increasing(Using multipler variable) ...
 
 if(multipler % 1000 == 0){
 //do stuff you want 
 }
 }
Comment
create3dgames
inwtaname

People who like this

2 Show 5 · 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 create3dgames · Jun 20, 2013 at 02:17 PM 0
Share

Converted to JS

 public var result : int = 0;
 public var multipler : int = 0;
  
  
 function Update(){
 //Numbers increasing(Using multipler variable) ...
  
 if(multipler % 1000 == 0){
 //do stuff you want 
 }
 }
avatar image Selevan · Jun 20, 2013 at 02:30 PM 0
Share

But this makes the code only if the turn counter is at 3000, then 6000 etc. I want it to notice if eg, the variable jumps between 750 and 1500.

avatar image Stormizin · Jun 20, 2013 at 02:35 PM 0
Share
 if(multipler >= 750 || multipler <= 1500){
 //Do what you log
 }

My question is: Do you want to know when the variable is between 750 and 1500? Or do you want to know where the variable is jumping 750 numbers?

avatar image Selevan · Jun 20, 2013 at 02:39 PM 0
Share

I want to know IF the variable hit full thousands, while jumping by 750 each "turn".

avatar image Stormizin · Jun 20, 2013 at 05:35 PM 0
Share

You can use the var result to check if the divisor has the rest equals integer, then you will know if is 1000, 2000, 3000 etc.

avatar image

Answer by MariuszKowalczyk · Jun 20, 2013 at 04:11 PM

To do what you want, you should probably do this:

 var counter : int = 0;
 
 function Update()
 {
     counter += 750; //example
 
     if (counter >= 1000)
     {
          counter -= 1000;

          //move your npc here
     }
 }
Comment

People who like this

0 Show 2 · 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 Selevan · Jun 20, 2013 at 04:41 PM 0
Share

But then it keeps adding 750 every frame.

avatar image MariuszKowalczyk · Jun 20, 2013 at 04:45 PM 0
Share

But then it keeps adding 750 every frame.

That's why I wrote //example. You can put that part when you need, the rest is important and doing what you want.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Wandering AI "ignores" speed 2 Answers

Influencing AI Movement With Bitmap? 0 Answers

Character moves slower after build 3 Answers

Help with Grid movement script + AI script 1 Answer

Enemy Movement Problem 2 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