- Home /
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";
}
Have you tested with print statements that number_of_objects actaully gets to 3?
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.
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);}
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.
PeterG, you are a noble defender of the focus of my 3am posts. And I appreciate it.