- Home /
Question by
sayu78 · Apr 28, 2019 at 04:55 PM ·
damagetower-defensebattle-systemhealth
Hi I want my enemies and character recognize with what they are colliding so they can -- the correct amount of damage , it's a tower defense kinda like battle cats game
characters script using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemymonitos : MonoBehaviour {
public float health;
public float starthealth;
public float force;
public float atkA;
public GameObject Debilidad;
private Monitos monitos;
private void Start()
{
health = starthealth;
}
void OnCollisionEnter2D(Collision2D coll)
{
Vector2 dir = (this.transform.position - coll.transform.position).normalized;
if (coll.gameObject.tag == "Player")
{
health -= monitos.atk;
this.transform.Translate(dir * force);
}
if (health <= 0)
{
Destroy(gameObject);
}
}
}
enemies script using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemymonitos : MonoBehaviour {
public float health;
public float starthealth;
public float force;
public float atkA;
public GameObject Debilidad;
private Monitos monitos;
private void Start()
{
health = starthealth;
}
void OnCollisionEnter2D(Collision2D coll)
{
Vector2 dir = (this.transform.position - coll.transform.position).normalized;
if (coll.gameObject.tag == "Player")
{
health -= monitos.atk;
this.transform.Translate(dir * force);
}
if (health <= 0)
{
Destroy(gameObject);
}
}
}
Comment
Your answer