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 /
This question was closed Apr 10, 2013 at 04:29 AM by Fattie for the following reason:

Question is off-topic or not relevant

avatar image
-1
Question by rednax20 · Jan 31, 2013 at 02:47 AM · instantiatevector3whiledo

While/Do loop problem(for all I know its something else)

I thought I had an idea of what I was doing, but I obviously don't. I am trying to get some monsters (Clizy) to instantiate in around the map, I just need them not to appear in the center. I also need them to randomly instantiate (but not in the middle) I worked except when both else statements were true. I know this probably won't make any sense, but if someone can point out my error, or another way to do this I would be very thankful. my error is this: .js(25,131): BCE0044: expecting ), found 'Quaternion'.

 function DecideXaxis (X : int, XVal : int){
     if(X <=1){
            XVal = Random.Range(-9, 15);
        } else if (X <= 2){
            XVal = Random.Range(-9, 90);
        }else XVal = Random.Range(75, 90);
        return XVal;
 }
 function DecideZaxis (Z : int, ZVal : int){
     if(Z <=1){
            ZVal = Random.Range(-9, 15);
        } else if (Z <= 2){
            ZVal = Random.Range(-9, 90);
        }else ZVal = Random.Range(75, 90);
        return ZVal;
 }
 var Clizy : GameObject; 
 var lightObject : Light; 
 function OnTriggerStay (other : Collider) {
        if(lightObject.enabled == true){ 
            if (other.CompareTag ("Respawn")) {
                    Destroy (other.gameObject); 
                    yield WaitForSeconds (1);
                    do {
                        Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))) Quaternion.identity);
                    } while(Z > 2 && X > 2) {
                        Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))) Quaternion.identity); 
                    }
         }
     }
 }
Comment
Add comment
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

3 Replies

  • Sort: 
avatar image
1
Best Answer Wiki

Answer by Danmietz · Jan 31, 2013 at 03:26 AM

I believe you're missing a comma following the position and before the quaternion; what you have is

 Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))) Quaternion.identity);

when you're after

 Instantiate (Clizy, Vector3(DecideXaxis(Random.Range(1,3), 0),-16,DecideZaxis(Random.Range(1,3))), Quaternion.identity);

Because there's no comma, it's giving you the error because it's assuming that's the end of the parameters you're passing in (position/rotation are optional in Instantiate()).

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
avatar image
1

Answer by Eric5h5 · Jan 31, 2013 at 03:35 AM

The format for do/while is

 do {
     // something
 }
 while (condition);

You appear to be trying to combine a standard while loop with a do/while loop, which isn't possible. However that would be an infinite loop anyway, since you never change Z or X inside the loop.

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
avatar image
0

Answer by rednax20 · Jan 31, 2013 at 10:57 PM

thanks guys you were a great help, not that anyone will need to use this but the finished code looks like this:

 function DecideXaxis (X : int, XVal : int){
     if(X <=1){
            XVal = Random.Range(-9, 90);
        }else if (X  <= 2){
            XVal = -10;
        }else if (X <= 3) {
            XVal = Random.Range(-9, 90);
        }else if (X  <= 4){
            XVal = 80;
        }
        return XVal;
 }
 function DecideZaxis (Z : int, ZVal : int){
     if(Z <=1){
            ZVal = 60;
        }else if (Z  <= 2){
            ZVal = Random.Range(-35, 65);
        }else if (ZVal <= 3) {
            ZVal = -30;
        }else if (Z  <= 4){
            ZVal = Random.Range(-35, 65);
        }
        return ZVal;
 }
 var Clizy : GameObject; // monster prefab
 var lightObject : Light; //light that activates the forcefeild
 function OnTriggerStay (other : Collider) {
     if(lightObject.enabled == true){ // if the light is on
            if (other.CompareTag ("Respawn")) {
                Destroy (other.gameObject); // destroy it
                yield WaitForSeconds (1.5);
                var number : int;
                number = Random.Range(1,4);
                Instantiate (Clizy, Vector3(DecideXaxis(number, 0),-16,DecideZaxis(number, 0)), Quaternion.identity);
         }
     }
 
 }

so if anyone is looking on this post looking for the actual answer to this question, it is here, but I couldn't have done it without you guys!! I was doing it all wrong anyway

Comment
Add comment · 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 Benproductions1 · Apr 10, 2013 at 01:37 AM 0
Share

Please finish this question off!!

avatar image rednax20 · Apr 10, 2013 at 02:32 AM 0
Share

wish i could can't close it.

I sorry if it is offensive that when I posted this I wanted to give the answer to someone else with my problem.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Can't instantiate in loop - crashes unity 1 Answer

Objects spawning in relation to resolution 1 Answer

Get rotation from hit object 1 Answer

Add 0.5f to Vector.Right on next instantiated object ? 1 Answer

[VECTOR 3]Spawning enemy at random position 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