|
Hi, I made script that causes that object that have that script explodes after some damage. Problem is, that i have many of these objects in scene end when one object takes the damage, one other in scene explodes. I don'n know where i made a mistake. Thanks for help. Here is the script:
var maxHealth : float;
static var currentHealth : float;
var dieSound : AudioClip;
var dieVisual : GameObject;
function Start()
{
currentHealth = maxHealth;
}
function Update()
{
if(currentHealth <= 0)
{
Destroy();
}
}
function Destroy()
{
AudioSource.PlayClipAtPoint(dieSound, transform.position);
Instantiate(dieVisual, transform.position, transform.rotation);
Destroy(gameObject);
}
(comments are locked)
|
|
static variables are stored globally, not per instance. so make it non-static (remove static keyword) I removed it, but it didn't help..
Aug 17 '12 at 11:03 AM
Arlei
you:
Aug 17 '12 at 11:13 AM
ScroodgeM
when there was static, all objects died at once, when i removed it, objects destroy one by one, but by order they are placed in hierarchy.
Aug 17 '12 at 12:18 PM
Arlei
then try to localize point that starts destroying. before you'd remove static it was caused by all objects have shared health and once it becomes <=0, all objects are destroyed. now there's something else goes wrong. check health of other objects - don't it goes to zero? if they dies with sound and visual effects, something runs Destroy() method - where else this method can be raised? etc
Aug 17 '12 at 01:52 PM
ScroodgeM
It destroys by order in hirearchy only objects from the same prefab. I still didn't figured out what's the problem..
Aug 17 '12 at 03:42 PM
Arlei
(comments are locked)
|
