Kinda area damage but with sword
I want to make trigger that will deal damage to every enemy in radious of this trigger. I dont know how to make it soo if u can help me pls.
thats my attack radious
Answer by juliacs · Apr 08, 2019 at 06:28 PM
You need to think the other way around: it isn't the trigger who causes damage, it's the enemies who are damaged when inside the trigger. You need to create an OnTriggerEnter method that will decrease your enemies' HP and attach the script to the enemy prefab/object.
i have last question look there are 2 enemies but only 1 take damage when he dies another is starting to take it
and here are my scripts
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AutoAtackScript : $$anonymous$$onoBehaviour
{
public bool IsActive;
public float cooldownAT$$anonymous$$, next_move, AT$$anonymous$$damage;
public void BtnAtack()
{
if(IsActive == false)
{
IsActive = true;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DamageRecieve : $$anonymous$$onoBehaviour
{
public Collider player;
public GameObject DealDamage;
public GameObject damage;
private void OnTriggerStay(Collider other)
{
if(damage.GetComponent<AutoAtackScript>().IsActive)
{
if (Time.time > damage.GetComponent<AutoAtackScript>().next_move)
{
DealDamage.GetComponent<Enemy>().DealDamage(damage.GetComponent<AutoAtackScript>().AT$$anonymous$$damage);
print("Enemy found");
damage.GetComponent<AutoAtackScript>().next_move = Time.time + damage.GetComponent<AutoAtackScript>().cooldownAT$$anonymous$$;
}
damage.GetComponent<AutoAtackScript>().IsActive = false;
}
}
}
if u can look at it and tell me what im doing wrong i will be very greatefull
Your answer
Follow this Question
Related Questions
Teleport using keypress (C#) 0 Answers
Can i tag collider? 1 Answer
Check if position is inside a collider 5 Answers
Spawning with trigger 2 Answers