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 jacksterooney · Jan 08, 2013 at 02:32 PM · javascriptbeginnerfloatfunctions

Weird Code Error Message

Here is the code I'm trying to compile:

 var scare : Transform;
 
 //create a random number between 1-0
 private var randomNumber = Random.Range;
 
 //activate trigger
 function onTriggerEnter (other:Collider) {
 
     if (other.gameObject.tag == "Player"){
     
         //create weighted number
         var chance = randomNumber * Screwedometer.screwedLevel;
         
         var decider = chance / 15000;
         
         if (Random.Range <= decider){
             
             ///stufftodogoeshere///
             
         }
     }
 }
         

However, it doesn't work and the error it is giving me is "Assets/Scripts/Trigger.js(13,43): BCE0051: Operator '*' cannot be used with a left hand side of type 'function(float, float): float' and a right hand side of type 'float'. "

Any ideas?

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 AlucardJay · Jan 08, 2013 at 02:38 PM 0
Share

Try putting your private var randomNumber = Random.Range; within the trigger function. I don't think Unity likes making calculations outside functions (I had a similar problem once declaring an array then trying to populate it outside a function). Just a suggestion =]

As Jordan stated and I overlooked, I think you want Random.value

2 Replies

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

Answer by Landern · Jan 08, 2013 at 02:40 PM

Isn't Range a function?

The usage should be a min and a max.

 private var randomNumber = Random.Range(0, 1);

Same thing in your if statement.

Comment
Add comment · Show 7 · 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 AlucardJay · Jan 08, 2013 at 02:41 PM 0
Share

agh, you're right. I read Random.value ins$$anonymous$$d of Random.Range !

avatar image Landern · Jan 08, 2013 at 02:51 PM 0
Share

I agree with alucardj, Random.value will give the value between 0.0-1.0 and is most likely what was intended.

avatar image jacksterooney · Jan 08, 2013 at 03:36 PM 0
Share

Thanks for the help, would that return a float value, like 0.235? Or does it just return either 1 or 0?

avatar image AlucardJay · Jan 08, 2013 at 03:38 PM 0
Share

Returns float value =]

API : http://docs.unity3d.com/Documentation/ScriptReference/Random-value.html

avatar image jacksterooney · Jan 08, 2013 at 03:39 PM 0
Share

Brilliant, it works perfectly. $$anonymous$$arking you as the answer, thanks again!

Show more comments
avatar image
3

Answer by tosi · Jan 08, 2013 at 02:47 PM

Random.Range is a function call. You should write: randomNumber = Random.Range(0,1);

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 AlucardJay · Jan 08, 2013 at 03:41 PM 0
Share

Stuck in the moderation que, hey! I shall upvote you too (upvoted Jordan already) =]

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

11 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

How fluent do I need to be in JavaScript before taking a crack at Unity's tutorials? 3 Answers

Help on selecting and unselecting a gameobject? 2 Answers

Script to teleport player (Beginner here) 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