x


Damage script is screwed up...? what to do?

Enemy script

var damage = 10;

function OnCollisionEnter (col : Collision) {

col.gameObject.BroadCastMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}

Player Script

var health = 50;

function ApplyDamage (damage : int) {
     health -= damage;

     if(health <= 0) {
         Die();
     }
}
function Die () {
   Application.LoadLevel (Application.loadedLevel); 
}

I used these both scripts, one on the cube and one on my player. But when the cube collides with my player, nothing special happens, it just walks past my player like nothing happened. What should i do? Does the problem lie on.... that's the problem... i don't know what should be taken care off.

PLZ help cause i'm.... lost and noob..

more ▼

asked Feb 27 '11 at 04:17 PM

Henry 3 gravatar image

Henry 3
1 2 2 2

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

1 answer: sort voted first

Hi,

Before you worry about the Messaging , you need to verify that the collision is happening.

-Does your Cube have a rigidbody attached to it?

-You need to know what are you colliding with.

--create a tag and add the tag to the Cube (I am using enemy in the example below) I added this to the player:

function OnCollisionEnter (col : Collision) {

if(col.gameObject.tag=="enemy"){

Debug.Log("Collision Happened");

}

}

If collision Happens then you need to deal with the rest

more ▼

answered Feb 27 '11 at 05:35 PM

rimawi gravatar image

rimawi
145 10 17 27

(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:

x3331
x805
x653
x383
x248

asked: Feb 27 '11 at 04:17 PM

Seen: 1201 times

Last Updated: Feb 27 '11 at 04:17 PM