- Home /
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..
Answer by rimawi · Feb 27, 2011 at 05:35 PM
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
Your answer
Follow this Question
Related Questions
Deduct health on collision 2 Answers
I use this script, but the enemy lose health if i don´t target him. 1 Answer
How to make Enemy AI and Health 1 Answer
Player Damage to enemy damage melee system 0 Answers
Problem with enemy health. 1 Answer