SFE_AsteroidController.js 715 B

1234567891011121314151617181920212223242526272829303132333435
  1. //despite the name, it controls everything that can be shot and does not have a shield.
  2. #pragma strict
  3. var impulseForce:float=10;
  4. var HPmin:float=3;
  5. var HPmax:float=6;
  6. private var HP:float;
  7. var explosion:GameObject;
  8. function Start () {
  9. HP=Random.Range(HPmin, HPmax);
  10. }
  11. function Update () {
  12. }
  13. function OnCollisionEnter(collision : Collision) {
  14. if (collision.gameObject.GetComponent(SFE_BulletController))
  15. HP-=collision.gameObject.GetComponent(SFE_BulletController).damage;
  16. if (collision.gameObject.GetComponent(SFE_LaserController))
  17. HP-=collision.gameObject.GetComponent(SFE_LaserController).damage;
  18. if (HP<=0)
  19. {
  20. Instantiate(explosion, transform.position, transform.rotation);
  21. Destroy (gameObject);
  22. }
  23. }