Hey,
i have a problem with my enemy script. i didn’t found the solution in similar topics.
I have 2 enemies (dublicated). My problem is, that the life of both is decreasing simultaneously.
Do you know why?
1. Enemyscript
public static var Health = 100;
static function Damage(){
if(Health > 0){
Health -= Cannon.myDamage;
Debug.Log(Health);
}
}
2. Cannonscript
var mySpeed : float = 10;
var myRange : float = 10;
public static var myDamage : float = 5;
private var myDist : float;
var counter = 1;
static var testname;
function Update ()
{
transform.Translate(Vector3.forward * Time.deltaTime * mySpeed);
myDist += Time.deltaTime * mySpeed;
if(myDist >= myRange){
Destroy(gameObject);
}
}
function OnCollisionEnter(collision: Collision)
{
if(collision.gameObject.tag == "Enemy")
{
if(collision.gameObject.name == "Enemy!"){
if(collision.gameObject.GetComponent(CubeEnemy).Health > 0){
collision.gameObject.GetComponent(CubeEnemy).Damage();}
if(collision.gameObject.GetComponent(CubeEnemy).Health <= 0){
Destroy (collision.gameObject);
}