My enemy projectiles challenge

,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Projectile : MonoBehaviour {

float damageCaused=10f;
[SerializeField] float projectileSpeed = 10f;
public float power = 50f;
Rigidbody rb;
void Awake()
{
    rb = GetComponent<Rigidbody>();
    rb.AddForce(transform.forward * power);


}
void OnTriggerEnter(Collider col)
{
  
    Component damagableComponent = col.gameObject.GetComponent(typeof(IDamageable));
   // print("damagableComponent" + damagableComponent);
    if (damagableComponent)
    {

        (damagableComponent as IDamageable).TakeDamage(damageCaused);//damage=damageCaused
    }
}

// Update is called once per frame

}

,
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);

}

}

Privacy & Terms