- Home /
 
Spawning and health script not working with collider?
var fireball : GameObject; var Spawnpoint : GameObject; var lifesleft = 3; var healthleft = 27; var damagefromball = 25;
 
               function awake () { Spawnpoint.transform.position = transform.position; }
 
               function OnTriggerEnter ( hit : Collider) { if(hit.GameObject(fireball)) { healthleft -= damagefromball; } }
 
               function Update () { if(healthleft <= 0) { lifesleft -= 1; forceRespawn(); }
 
                if(lifesleft >= 1) { Destroy.GameObject; }
 
               }
  
               function forceRespawn () { transform.position = SpawnPoint.transform.position; } 
I'm pretty sure I'm just missing something from it. I just really need another set off eyes to catch my problem for me. Help please?
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Bunny83 · Feb 26, 2011 at 02:16 AM
Here we go:
- Well, at respawn you have to set the "healthleft" back to full health ( 27 ? ).
 - hit don't have a GameObject just a gameObject but you used it like a function. I'm not sure what you want to check here as condition. Maybe checking the tag would be simpler for you.
 - next thing is the object get destroyed if lifesleft are greater or equal 1, that means immediately! Change it to less than 1.
 - Thw whole stuff in update can be in OnTriggerEnter at the end
 - And finally what object is assigned to "Spawnpoint" and why it it moved to the objects position in awake? I guess you just want to save the initial position? Use a Vector3 to save a position.
 - For readabillity use camelCase for variable names and PascalCase for function names.
 - and indent at least 3
 
Your answer