x


Health subtracts when hit by bullit

Hey i'm currently trying to make a 2D platformer, and i've reached the stage where i want to make the enemies work out, so what i'm currently strangling with is to make a script that subtracts my 1 of my ¨hearths¨ ( I have made a GUI-texture and placed out some hearths, and i've also made a enemy that shoots towards my character)

Here's my healthcontroll script so far :

var health1 : Texture2D; //one life left

var health2 : Texture2D; //two life left

var health3 : Texture2D; //full heatlh

static var LIVES = 3;

function Update (){

 switch(LIVES)

 {    

 case 3:

     guiTexture.texture = health3;

 break;

 

 case 2:

     guiTexture.texture = health2;

 break;

 

 case 1: 

     guiTexture.texture = health1;

 break;

 

 case 0:

     //game over script here

 break;

 }

}

So i know i'll have to make script that will subtract my ¨LIVES¨, does anyone have a example of such a script? would love to get this scripting done :)

more ▼

asked Mar 14, 2012 at 08:44 PM

Alaro gravatar image

Alaro
16 21 14 15

Why have you shown us the part of the script that is working perfectly? It's kind of irrelevant. How do your bullets work? Do they follow a predetermined path, or are they physics based?

Mar 14, 2012 at 09:27 PM syclamoth
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The script was just to illustrate how far i've gotten, and the bullets are physic-based ¨spheres¨.

more ▼

answered Mar 15, 2012 at 01:37 AM

Alaro gravatar image

Alaro
16 21 14 15

(comments are locked)
10|3000 characters needed characters left

you can call a function in this script to detect any collision by doing:

  function OnCollisionEnter(collider: Collision) {
     LIVES--;
     }


or if you want to tag your Sphere to detect just when it hits the player you can attach a tag called "Sphere" in the sphere and make an if statement inside OnCollisionEnter function to check the tag of the collider, like:

   function OnCollisionEnter(collider: Collision) {
     if(collider.transform.tag == "Sphere") {
     LIVES--;
     }
     }
more ▼

answered Mar 15, 2012 at 02:04 AM

GutoThomas gravatar image

GutoThomas
718 109 92 98

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x9411
x3235
x617
x363
x163

asked: Mar 14, 2012 at 08:44 PM

Seen: 1132 times

Last Updated: Mar 15, 2012 at 02:13 AM