Hi there,
I want to reduce health from the enemy ( Character Controller ) when the Projectile hit this prefab but i can’t get it working , i tried several script and method but without success,
Here is my latest try ( javascript ) :
var Power: int = 5;
// var Enemy: GameObject;
function OnControllerColliderHit(hit: ControllerColliderHit){
if (hit.tag == "Enemy"){
hit.GetComponent("EnemyHealth1").AdjustCurrentHealth(-Power);
Debug.Log("Enemy lost :"+ Power +"PV");
}
}
EDIT : SOLUTION
I just found the solution !!
Here is the corrected Script ;
var Power: int = 5;
var Effect: GameObject; // if you want to spawn an collision effect
function OnCollisionEnter(collision : Collision) {
Instantiate(Effect, transform.position + Vector3.up, Quaternion.identity); // Instantiate the collision effect
if (collision.gameObject.tag == "Enemy") {
collision.gameObject.GetComponent(EnemyHealth1).AdjustCurrentHealth(-Power);
Debug.Log("Enemy lost :"+ Power +"PV");
}
}