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 destroyersmark · Nov 22, 2013 at 03:41 AM · random.rangeintegercompareadding

How do you add an integer to a random.range?

Working on a lock picking scenario and I am having troubles on figuring out how to add int to a random.range. The int is the lock picking skill currently possessed by the player, and the random.range is the rolled numeral needed to pick the lock. I also have a set numeral that defines the lock strength which is 10. The int needs to be added to the random.range to be >= the lock strength to pick it.

This is for my lock:

 var DoorOpen : boolean = false;
 var randomNumber : int = 0;
 var LockStrength : int = 10;
 
 function Start () {
 
 }
 
 function Update () {
 
 
 
 }
 
 function OnMouseDown (){
     randomNumber = Random.Range(1,8);
     print(randomNumber);
 
         
         
             if(DoorOpen == true){
             animation.Play("door1anim");
             }
 
             
 
 }
 
 
 

This is for my character:

 var wire : Door1;
 var PickSkill = 5;
 
 function Start () {
 
 }
 
 function Update () {
 
 }




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 iwaldrop · Nov 22, 2013 at 07:31 AM 0
Share

I formatted your code for you, but please, in the future, use the little button marked with the '101010' to paste code. Thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Programmer-Tau · Nov 22, 2013 at 05:44 AM

You mean something like this?

 function OnMouseDown() {
      var randomNumber = Random.Range(1,8)+5; // 5 is the PickSkill
      if (randomNumber >= LockStrength) {
           animation.Play("door1anim");
      }
 }


Now how you reference the variable PickSkill, rather than hardcoding the number 5 is a topic for a whole new question.

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

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

18 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

Related Questions

Int doesn't add until after I exit playmode. 1 Answer

How can I make the Random.Range in this spawning script a PUBLIC adjustable variable? The (0, 35) code limit gives errors when I need the prefab list to fluctuate. An example code would help. Thanks! 1 Answer

How do I randomly change whether a mesh is on or off for an object, based on another object updating? 0 Answers

Set integer to new random value every time Update() runs 1 Answer

Random.Range is not changing? 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