Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Catlard · Jun 04, 2011 at 12:50 PM · instantiateinstantiation

Cloud objects not instantiating (Oh no!).

UPDATE: So, when I replace the "flower" transform in the flower's instantiation to other objects, like the clouds, they do appear where the flower's supposed to be. So I know it's not the objects causing it. It's the way I'm running StartLoop. Any Ideas?

Hey, y'all.

So, I'm working on this script, which is designed to instantiate a series of objects at certain times. The script works for the first two objects I'm instantiating, but not the third. the objects are assigned correctly in the inspector...when I look at them there, they highlight the correct objects. But for some reason, it's not entering a certain part of the code which appears to be identical to other parts. It's commented out to show you what's wrong, with a big line in caps where the error is.

If you can figure this out, I will gladly name my first born child after you. I think it's just a syntax error...forgive me my long, brutish script. I hope it has enough comments.

Cheers,

Simon

 var maincamera:Camera;
 var eyeofbeholder : GameObject;
 var destroyer;
 destroyer = eyeofbeholder.GetComponent("Character Destroyer");
 var GUIscript;
 GUIscript = eyeofbeholder.GetComponent("Basic GUI");
 
 var flower:Transform;
 var bee:Transform;
 var cloud:Transform;
 var butterfly:Transform;
 var sign:Transform;
 var mesa:Transform;
 var mushroom:Transform;
 var tree:Transform;
 var cow:Transform;
 var rock:Transform;
 var rainbow:Transform;
 
 var loop_length = 18;
 var number_of_objects = 0;
 var mybeat;
 var timecount = 0.00;
 var roundedtime;
 var currentbeat = 0.00;
 var side = 1;
 var put_objects_into_loop = false;
 var aa = 0.000;
 var roundedcounter=0.000;
 
 //i always want to start the music loop, so that it will place objects that are already supposed to be placed when the loop restarts.
 function Start()
 {
     StartLoop();
 }
 //in the update function, i find the time in seconds rounded to the nearest eighth of a second. when it increases and it's time to update the number of objects in the loop, and place them before StartLoop() is called again automatically by itself every 18 seconds (when roundedcounter resets).
 function Update()
 {
     timecount += Time.deltaTime;
     roundedtime = Mathf.Floor(timecount * 8) / 8;
     if(roundedtime > roundedcounter)
     {
         roundedcounter = roundedtime;
         if(put_objects_into_loop)
         {
             StartLoop();
         }
     }
     if(number_of_objects != destroyer.combocount)
     {
         number_of_objects = destroyer.combocount;
         put_objects_into_loop = true;
     }
     if(timecount >= loop_length)
     {
         timecount = 0;    
     }
 }
 
 //this function, when called, places the objects on the "road" you're walking down in regular intervals that I dictate.
 function StartLoop()
 {
     //factors of 144 are 1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 36, 48, 72, 144, so when i give InvokeObjects a divisor parameter, it needs to be divisible by that.
     if(number_of_objects >= 1) InvokeObjects(4, "Flower", 1);
     if(number_of_objects >= 2) InvokeObjects(16, "Bee", 2);
     //NEXT LINE IS WHERE THE PROBLEM IS, LOOK HERE! this line of code is where the problem is. for some reason, when number_of_objects = 3, it doesn't go in here. I can see in the hierarchy that it's just not creating copies of the Cloud object or any object which I'm putting in that slot. When I put in print functions, I find out that it's not even going in here when number_of_objects = 3. What gives?
     if(number_of_objects >= 3) InvokeObjects(36, "Cloud", 3);
     if(number_of_objects >= 4) InvokeObjects(16, "Butterfly", 4);
     if(number_of_objects >= 5) InvokeObjects(16, "Sign", 5);
     if(number_of_objects >= 6) InvokeObjects(16, "Mesa", 6);
     if(number_of_objects >= 7) InvokeObjects(16, "Mushroom", 7);
     if(number_of_objects >= 8) InvokeObjects(16, "Tree", 8);
     if(number_of_objects >= 9) InvokeObjects(16, "Cow", 9);
     if(number_of_objects >= 10) InvokeObjects(16, "Rock", 10);
     if(number_of_objects >= 11) InvokeObjects(16, "Rainbow", 11);
     if(!put_objects_into_loop) Invoke("StartLoop", loop_length);
     put_objects_into_loop = false;
 }
 
 //this invokes the objects to be instantiated at the correct time.
 function InvokeObjects(divisor:int, what_to_call: String, thislevel:int)
 {
     if(!put_objects_into_loop)
     {
         for(aa = 0; aa < 144; aa++)
         {
             if(aa%divisor == 0)
             {
                 Invoke(what_to_call, aa/8);
             }
         }
     }
     if(put_objects_into_loop && thislevel == number_of_objects)
     {
         for(aa = roundedcounter * 8; aa < 144; aa++)
         {
             if(aa%divisor == 0)
             {
                 print("invoked some shit");
                 Invoke(what_to_call, aa/8-roundedcounter);
             }
         }
     }
 }
 
 //this is the series of instantiating functions for each object. eventually, they will all need different variables.
 function Flower()
 {
     mybeat = Instantiate (flower, Vector3(4.5 * side, 1.25, transform.position.z+maincamera.farClipPlane-.5),  Quaternion.identity);
     mybeat.tag = "Flower";
 }
 
 function Bee()
 {
     mybeat = Instantiate (bee, Vector3(-4.5, 3, transform.position.z+maincamera.farClipPlane-.5),  Quaternion.identity);
     mybeat.tag = "Bee";
     mybeat.transform.Rotate(0,270,180);
 }
 
 function Cloud()
 {
     mybeat = Instantiate (cloud, Vector3(5, 14, transform.position.z+maincamera.farClipPlane-.5),  Quaternion.identity);
     mybeat.tag = "Cloud";
 }
 
 function Butterfly()
 {
     mybeat = Instantiate (butterfly, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5),  Quaternion.identity);
     mybeat.tag = "Butterfly";
 }
 
 function Sign()
 {
     mybeat = Instantiate (sign, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5),  Quaternion.identity);
     mybeat.tag = "Sign";
 }
 
 function Mesa()
 {
     mybeat = Instantiate (mesa, Vector3(-20, 3, transform.position.z+maincamera.farClipPlane-.5),  Quaternion.identity);
     mybeat.tag = "Mesa";
 }
 
 function Mushroom()
 {
     mybeat = Instantiate (mushroom, Vector3(-10, 1.7, transform.position.z+maincamera.farClipPlane),  Quaternion.identity);
     mybeat.tag = "Mushroom";
 }
 
 function Tree()
 {
     mybeat = Instantiate (tree, Vector3(-10, 1.7, transform.position.z+maincamera.farClipPlane),  Quaternion.identity);
     mybeat.tag = "Tree";
 }
 function Cow()
 {
     mybeat = Instantiate (cow, Vector3(-10, 1.7, transform.position.z+maincamera.farClipPlane),  Quaternion.identity);
     mybeat.tag = "Cow";
 }
 
 function Rock()
 {
     mybeat = Instantiate (rock, Vector3(10, 1.7, transform.position.z+maincamera.farClipPlane+1),  Quaternion.identity);
     mybeat.tag = "Rock";
 }
 
 function Rainbow()
 {
     mybeat = Instantiate (rainbow, Vector3(10, 1.7, transform.position.z+maincamera.farClipPlane+1),  Quaternion.identity);
     mybeat.tag = "Rainbow";
 }

Comment
Add comment · Show 10
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 GesterX · Jun 04, 2011 at 01:51 PM 0
Share

Have you tested with print statements that number_of_objects actaully gets to 3?

avatar image Catlard · Jun 04, 2011 at 02:55 PM 0
Share

Yes, I have, good call. It definitely does. I can see it in the inspector, and I've had the program print it to the debug log.

avatar image GesterX · Jun 04, 2011 at 03:56 PM 0
Share

The first thing I would advise is to use currly brackets with your if statements:

e.g.

if(number_of_objects >= 7) {InvokeObjects(16, "$$anonymous$$ushroom", 7);}
avatar image Peter G · Jun 04, 2011 at 03:59 PM 0
Share

I can confirm with you UPDATE that I have trouble loading .ma and .mb files on my computer since I don't have $$anonymous$$aya.

avatar image Catlard · Jun 04, 2011 at 04:08 PM 1
Share

PeterG, you are a noble defender of the focus of my 3am posts. And I appreciate it.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GameObject instantiation in C# static constructor 2 Answers

Inconsistencies in Instantiation Code 1 Answer

Instantiating enemies in spawn points not working on Android Build 0 Answers

Problem with object pooling and reseting the properties of a pooled object 0 Answers

Instantation and use of gameobject in same frame 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