hello, ive created a script that when an heroe gets within the trigger of a enemy the enemy would then be able to tell what heroe entered and then only damage the heroes that are in its trigger effect. But it doesnt seem to work, unity has given me a few errors, one of them saying that Distance has already been used and i dont really know how to alter my script so that it works. Please help, thanks in advance, heres my script
using UnityEngine;
using System.Collections;
public class EnemyAttack1 : MonoBehaviour {
public GameObject target;
public GameObject target2;
public bool Knightbool = false;
public bool Linemanbool = false;
public float attackTimer;
public float coolDown;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 2.0f;
}
// Update is called once per frame
void Update () {{
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer <0)
attackTimer = 0;
if(attackTimer == 0) {
OnTriggerEnter();
attackTimer = coolDown;
if(attackTimer == 2.0f){
GetComponent<EnemyAttack1>().enabled = false;
}
}
}
}
void OnTriggerEnter(Collider Col) {{
if(Col.gameObject.tag == "Lineman"){
target = GameObject.Find ("Lineman");
Linemanbool = true;
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
if(distance < 100.5f) {
LinemanHealth lh = (LinemanHealth)target.GetComponent("LinemanHealth");
lh.AdjustCurrentHealth(-10);
}
}
if(Col.gameObject.tag == "Knight"){
target = GameObject.Find("Knight");
Knightbool = true;
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
if(distance < 100.5f) {
KnightHealth kh = (KnightHealth)target.GetComponent("KnightHealth");
kh.AdjustCurrentHealth(-10);
}
}
if(Col.gameObject.tag == "Knight" && Linemanbool == true){
target = GameObject.Find("Knight");
target2 = GameObject.Find("Lineman");
float distance = Vector3.Distance(target && target2.transform.position, transform.position);
Vector3 dir = (target && target2.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
if(distance < 100.5f) {
LinemanHealth lh = (LinemanHealth)target2.GetComponent("LinemanHealth");
lh.AdjustCurrentHealth(-10);
KnightHealth kh = (KnightHealth)target.GetComponent("KnightHealth");
kh.AdjustCurrentHealth(-10);
}
}
}
}
}