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 JacobHockey13 · Apr 22, 2014 at 12:15 AM · instantiatemathf.clampbce0043dot

Instantiating Dots

 #pragma strict
 
 var dotcyan : GameObject;
 var dotred : GameObject; 
 var dotgreen : GameObject;
 var dotyellow : GameObject;
 var dotorange : GameObject;
 
 function awake () {
   var Mathf.Clamp01 : float;

   if (Mathf.Clamp01 < .2) {
   Instantiate (dotcyan,0,0);
   } else if (.2 <= Mathf.Clamp01 < .4) {
   Instantiate (dotred,0,0);
   } else if (.4 <= Mathf.Clamp01 < .6) {
   Instantiate (dotgreen,0,0);
   } else if (.6 <= Mathf.Clamp01 < .8) {
   Instantiate (dotyellow,0,0);
   } else if (.8 <= Mathf.Clamp01 < 1) {
   Instantiate (dotorange,0,0);
   }
   }

I am trying to randomly instantiate one of the five prefabs I have created. I am getting error BCE0043. Would Mathf.Clamp01 be the appropriate method? Once this works, I want to repeat it with different transforms. Thanks to anyone who helps.

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 Eric5h5 · Apr 22, 2014 at 12:27 AM 0
Share

You really should use an array, not a bunch of separate variables.

1 Reply

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

Answer by getyour411 · Apr 22, 2014 at 12:25 AM

Take a look at the UA/Google examples of using Mathf.Clamp01 and Random()

http://forum.unity3d.com/threads/82050-Mathf-Clamp01-always-return-1

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

Comment
Add comment · Show 8 · 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 JacobHockey13 · Apr 22, 2014 at 02:55 AM 0
Share

Thank you. I changed my code to reflect a correct usage with $$anonymous$$athf.Clamp01. However, I still quite can't get the code to run. I'm getting these three types of errors: (13,22): BCE0051: Operator '<' cannot be used with a left hand side of type 'boolean' and a right hand side of type 'float', (14,15): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(String, int, int)' was found, (10,25): BCE0022: Cannot convert 'function(float): float' to 'float'.

The current code is as follows

 #pragma strict
  
 var dotcyan : GameObject;
 var dotred : GameObject; 
 var dotgreen : GameObject;
 var dotyellow : GameObject;
 var dotorange : GameObject;
  
 function awake () {
   var i : float = $$anonymous$$athf.Clamp01; 
   if (i < .2) {
   Instantiate ("dotcyan",0,0);
   } else if (.2 <= i < .4) {
   Instantiate ("dotred",0,0);
   } else if (.4 <= i < .6) {
   Instantiate ("dotgreen",0,0);
   } else if (.6 <= i < .8) {
   Instantiate ("dotyellow",0,0);
   } else if (.8 <= i < 1) {
   Instantiate ("dotorange",0,0);
   }
avatar image JacobHockey13 · Apr 22, 2014 at 02:57 AM 0
Share

Thank you. I changed my code to reflect a correct usage with $$anonymous$$athf.Clamp01. However, I still quite can't get the code to run. I'm getting these three types of errors: (13,22): BCE0051: Operator '<' cannot be used with a left hand side of type 'boolean' and a right hand side of type 'float', (14,15): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(String, int, int)' was found, (10,25): BCE0022: Cannot convert 'function(float): float' to 'float'.

The current code is as follows

 #pragma strict
  
 var dotcyan : GameObject;
 var dotred : GameObject; 
 var dotgreen : GameObject;
 var dotyellow : GameObject;
 var dotorange : GameObject;
  
 function awake () {
   var i : float = $$anonymous$$athf.Clamp01; 
   if (i < .2) {
   Instantiate ("dotcyan",0,0);
   } else if (.2 <= i < .4) {
   Instantiate ("dotred",0,0);
   } else if (.4 <= i < .6) {
   Instantiate ("dotgreen",0,0);
   } else if (.6 <= i < .8) {
   Instantiate ("dotyellow",0,0);
   } else if (.8 <= i < 1) {
   Instantiate ("dotorange",0,0);
   }
avatar image getyour411 · Apr 23, 2014 at 04:19 AM 0
Share

Change this

 var i : float = $$anonymous$$athf.Clamp01; 

to this

 var i : float = Random.value;

 

and capitalize Awake

avatar image JacobHockey13 · Apr 29, 2014 at 01:10 AM 0
Share

Thank you getyour411. You have been a big help. I now realize that $$anonymous$$athf.Clamp01 "clamps" a variable, and doesn't assign it a value. I made the changes you suggested but I am still getting errors BCE0051 and BCE0023. Here is the current code

 #pragma strict
 
 var dotcyan : GameObject;
 var dotred : GameObject; 
 var dotgreen : GameObject;
 var dotyellow : GameObject;
 var dotorange : GameObject;
 
 function Awake () {
  var i : float = Random.value;
   if (i < 0.2) {
   Instantiate ("dotcyan",0,0);
   } else if (0.2 <= i < 0.4) {
   Instantiate ("dotred",0,0);
   } else if (0.4 <= i < 0.6) {
   Instantiate ("dotgreen",0,0);
   } else if (0.6 <= i < 0.8) {
   Instantiate ("dotyellow",0,0);
   } else if (0.8 <= i < 1.0) {
   Instantiate ("dotorange",0,0);
   }
   }

alt text

screen shot 2014-04-28 at 5.44.55 pm.png (58.3 kB)
avatar image getyour411 · Apr 29, 2014 at 01:16 AM 0
Share

I have not seen seen that form of if(x < i < y) before, it may not be valid. Did you see that somewhere in the C# language reference?

Change that to

 if( x <= i && i < y)

also where x or y is a decimal (i.e 0.4) make it 0.04f. Finally instantiate takes an Object, position and rotation and object is not a string, remove the quotes around dotCOLOR and take a look at Instantiate doc for position and rotation arguments

Show more comments

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

22 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

Related Questions

Checking if object intersects? 1 Answer

EventSystem: how to highlight instantiated button? 1 Answer

Instantiate moving prefab 1 Answer

I want to make a gun with 2 parts and follow their positions and scales 2 Answers

Instantiated Object Not Animating 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