- Home /
I did Coalition damage base on distance its not working
other kind of damage except collision is not working please take not I "cannot" use "Is trigger" kind of damage because it affects the physics of the game like a car crash and air crash. I will modify the damage based on magnitude after the script works
using UnityEngine; using UnityEngine.UI;
public class Enemy : MonoBehaviour {
public float startHealth = 200;
private float health;
public float EnemyDistance;
public GameObject playerObj ;
public GameObject enemyObj;
[Header("Unity Stuff")]
public Image healthBar;
public float collisiondamage = 50;
private bool isDead = false;
void Start() { playerObj = GameObject.FindGameObjectWithTag("Player"); enemyObj = GameObject.FindGameObjectWithTag("Enemy");
health = startHealth;
}
public void LateUpdate()
{
EnemyDistance = Vector3.Distance(playerObj.transform.position, enemyObj.transform.position);
health = startHealth;
if (health <= 0 && !isDead)
{
Die();
}
}
public void Takedamagesix()
{
if (EnemyDistance <= 1.35)
{ health -= collisiondamage; }
}
void Die()
{
isDead = true;
Destroy(gameObject);
}
}
Answer by janjoeljanjoel · Aug 06, 2020 at 09:58 AM
Edit it works now problem it destroys any enemy in less than a second any suggestion? for those who gonna copy-paste, it works by cut/paste the if statement under void late update
edit: I'm now using *Time.deltaTime Im now just adjusting the parameters
Your answer
Follow this Question
Related Questions
Does anyone know how to make a timer with HH/MM/SS in JS? 0 Answers
How would i make randomized exit points in a game? 2 Answers
One script for several objects OR Several scripts for several objects 0 Answers
make enemy stop at distance and play animation 1 Answer
How to set limits to the rotation of an object with the mouse? 2 Answers