,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;
using UnityEngine.UI;
public class Enemy : MonoBehaviour,IDamageable {
AICharacterControl aiCharacterControl=null;
[SerializeField] float maxHealthPoints=100f;
[SerializeField] float attackRadius=3f;
[SerializeField] float damagePerShot = 9f;
[SerializeField] float chaseRadius = 10f;
[SerializeField] GameObject projectileToUse;
[SerializeField] GameObject projectileSocket;
float currentHealthPoints=100f;
GameObject player=null;
public float healthAsPercentage
{
get
{
return currentHealthPoints / maxHealthPoints;
}
}
public void TakeDamage(float damage){//DAMAGEABLE COMPONENT WiTH ıNTERFACE ::)
currentHealthPoints = Mathf.Clamp (currentHealthPoints - damage, 0f, maxHealthPoints);
}
void Start(){
player = GameObject.FindGameObjectWithTag ("Player");
aiCharacterControl = GetComponent<AICharacterControl> ();
}
void Update()
{
float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);
if (distanceToPlayer < attackRadius)
{
print(gameObject.name + "attacking Player");
Instantiate(projectileToUse, projectileSocket.transform.position, projectileSocket.transform.rotation);
}
//TODO firing projectile
if (distanceToPlayer < chaseRadius)
{
aiCharacterControl.SetTarget(player.transform);
} else {
aiCharacterControl.SetTarget (transform);
}
}
void OnDrawGizmos()
{
// Draw attack sphere
Gizmos.color = new Color(255f, 0, 0, .5f);
Gizmos.DrawWireSphere(transform.position, attackRadius);
Gizmos.color = Color.blue;// new Color(255f, 0, 0, .5f);
Gizmos.DrawWireSphere(transform.position, chaseRadius);
}
}