- Home /
Question is too vague. problem was not what i thought it was
What the heck in going on? after 2.36 seconds the code just stops
I am making a game in which finger drags create lava on the ground. each frame a lava sprite (sprites made in unity 2d toolkit) in made from where the last finger touch was,
var flameball : GameObject;
function OnTriggerEnter(other : Collider){
print("collidied");
if(other.name == "Ground"){
for(var i = 0; i < 20; i++){
Instantiate(flameball, transform.position, Quaternion.identity);
}
print(Time.time);
}
}
as you can see, i have two print functions in the code, at approximately (2.34-2.38) 2.36 seconds both the Time.time print statement and the "collided" print statement stop printing, and the flame balls stop instantiating. even though i am still making new lava sprites.
the prefab doesn't change any parameters at this time. upon pausing i can see that the prefabs still have their script attached. just don't get it. Any ideas? and yes, the sprites do have a box collider on them with isTriggered checked.
OnTriggerEnter is called only once when object started colliding with trigger. Try to use (if i'm not wrong with the name) OnTriggerStayed.
its OnTriggerStay, just so you know, and i know that it only is called once, i only want it called once.
I want each of the new lava prefabs to work once, the lava prefabs that i make after 2.36 seconds don't do anything. the few before that time do work. it is very strange.
Answer by BlueRaja_2014 · Feb 10, 2014 at 09:15 PM
You are instantiating flameballs inside the trigger area. Are those causing OnTriggerEnter
to be called as well?
If you spawn 20 fireballs, and each of those spawn 20 more, and each of those...
no flameballs are on a no collision layer that i made not collide with anything in the project settings.
sorry should have told you.
@rednax20 in that case, have you tried stepping through the code to see what's going on?
I did but as you can see there is very little to step through, and my print statements within the code were my attempt to find the problem. that is how i found out the time.
when nothing turned up i decided to ask if there was anything obviously wrong with my code.
maybe there's something about on trigger enter that i didn't understand (like maybe sprites make it go crazy).
i have used o trigger enter with sprite before though and it has worked
I don t really know if i am going to be able to give you enough information for you to be able to figure it out,
if there is another script you'd like me to post that you think will help, then by all means i will. I just can't figure it out myself.
sorry i asked such a vague question i wish i knew more.
scratch that i tested it without the sprite. i did everything with a cube ins$$anonymous$$d, and it worked.
it must be something wrong with the sprite
not sure why. i will have to look up on it now that i know whats wrong. thanks for your help
Follow this Question
Related Questions
Instantiated Sprite is not rendering. 1 Answer
My script only makes two clones. 3 Answers
Animator not playing proper animations when Instantiating multiples of the same Prefab 0 Answers
Rotating a sprite toward the mouse position on instantiation. 0 Answers
Change a prefab sprite using Random.range instantiate in a script 3 Answers