I cannot for the life of me access a light inside of a prefab I am instantiating to destroy the light. Yes I want to destroy the light not turn it off. Here is the script along with some of the commands I have tried unsuccessfully. I have tried a every possible combination of the following commands just trying to delete this light I have instantiated as part of a prefab. PLEASE HELP.
start code:
var bullit : Transform;
var spreaderx : float;
var spreadery : float;
var spreaderz : float;
var light2 : Transform;
var lighter : GameObject;
var lighter2 : GameObject;
var lighter3 : GameObject;
function FixedUpdate () {
I can destroy normal gameobjects no problem, infact I can even child and unchild from a gameobject and then destroy that gameobject. I can even destroy the light if it is not part of a prefab, but once I create the prefab, I CANNOT DESTROY THE LIGHT.
I can get around this by simply creating 2 instantiated prefabs, 1st being the explosion, the 2nd being the light. Then I can delete the light.
Although I can “MICKEY MOUSE” this by creating 2 prefabs I will not resort to inferior coding just to get the job done. I need to know how to find this light in my prefab and delete it, thank you.
All that matters is the end result! People playing your game wont know how you deleted the light.
With that said, I have no idea how to solve your problem I would just go with the work around and move on.
With Light do you mean a Child GameObject with the name “Light” or the Light Component? For the later you should use GetComponent instead of Find and for the first one you should not use GameObject.Find to seach all objects but instead Transform.Find:
thanks guys. i will try this c# script that ram suggested. mark what i mean is its a prefab, and it has a child object named light which is a spotlight that i created. this is all in an attempt to make an explosion more realistic with lighting effects that are deleted less than a second after the explosion goes off to give an ambient lighting effect.
here is how the prefab looks:
explosion1prefab
-embers
-firecloud
-light <-------- spotlight i am trying to delete
-particle1
-particle2
-particle3
-particle4
-particle5
-smokey1
-smokey2
-sparks1
ok now I am back to another basic problem, I cannot put a float delay on the light delete.
Destroy(tempObject.gameObject, 1); this command works
Destroy(tempObject.gameObject, .1); this command does not work
yield WaitForSeconds(2); this command does not work, what the hell?
HOW CAN I PUT A SIMPLE .1 second PAUSE BEFORE MY LIGHT GETS DELETED THANKS…
No, don’t destroy objects. Just hide it and re-use it when you want to use it again. Otherwise, you’ll get some major CPU overhead from the garbage collector.
That’s false. F means float, which you can use if you have a float variable and want to assign a non-float value to it.
//This will work:
float myfloat = 0;
//This is better because you're being explicit:
float myfloat = 0F;
//This won't work:
float myfloat = 0.0;
//This is required:
float myfloat = 0.0F;
Actually its true. And you just proved it in your own post. Well done /slow clap
float f1 = 0; // fine. no decimal place
float f1 = 0f; // fine. no decimal place
float f1 = 0.0; //fails… has a decimal place… needs the f.
float f1 = 0.0f; //fine. has a decimal place and an f
In fact he is right, the f postfix just marks the value as a float type, leave it away and use a decimal place and you got a double.
0f is in fact a value with an decimal place, a float, even if you dont type out the dot.
float f1 = 0.0 only fails because you cant assign a double to a float value, thats all.
double d1 = 0; // fine
double d2 = 0f; // fine
double d3 = 0.0f; // fine
double d3 = 0.0; // fine
double d4 = 0.0M; // fails, even if its a decimal point
decimal d5 = 0.0M; // fine
His response was to your statement that every decimal in C# needs to have f appended to it - which is inaccurate. Maybe try to be a bit more respectful?