void Scan() { float minDist = detectRange; Vector3 ownPos = transform.position; bool found = false; foreach(GameObject t in GameObject.FindGameObjectsWithTag("Enemy")) { float dist = Vector3.Distance(t.transform.position, ownPos); if(dist < minDist) { found = true; currentTarget = t; minDist = dist; } } if (found) { state = turretStates.ATTACK; } else { state = turretStates.IDLE; } }
void Idle() { scanTimer += Time.deltaTime; if (scanTimer > scanFrequency) { scanTimer = 0; state = turretStates.SCAN; } }
void Attack() { float dist = Vector3.Distance (currentTarget.transform.position, transform.position); if (dist > detectRange) { state = turretStates.IDLE; } if (dist > firingRange) { state = turretStates.CHASE; } else { // Actual attack // To Do: Animation, projectiles // Animation timer // If animation timer finish for(int i = 0; i < i; ++i) // x being number of bullets fired during the animation { int accuracy = Random.Range(0, 101); if(accuracy < firingAccuracy) { // Minus health //currentTarget.GetComponent<MobStat>().health // If mob dies // state = turrentStates.IDLE; } } } }
// Use this for initialization void Start () { state = turretStates.IDLE; }