I have managed to use raycasting on selecting targeted enemies and making them red when targeted but now I need something like a spot light or a halo underneath the enemy to make it look better, so how would I got about having a spot light follow my targeted enemy? Thanks in advance ![]()
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
public float attackTimer;
public float coolDown;
public bool newon = true;
// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 2.0f;
}
// Update is called once per frame
void Update () {
if( Input.GetMouseButtonDown(0) newon == true)
{
Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
RaycastHit hit;
if( Physics.Raycast( ray, out hit, 100 ) )
{
float distance = Vector3.Distance(hit.transform.position, transform.position);
if(distance < 8) {
string hitTag = hit.transform.tag;
if (hitTag == "enemy")
{
Debug.Log( hit.transform.gameObject.name );
target = hit.transform.gameObject;
SelectTarget();
}
if( Input.GetMouseButtonDown(0) distance > 8)
{
DeselectTarget();
}
}
}
}
if (Input.GetMouseButtonDown (1)) {
DeselectTarget();
}
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
//attack press F key
if (Input.GetKey (KeyCode.F)) {
if(attackTimer == 0) {
Attack();
attackTimer = coolDown;
}
}
}
// CHANGE TO HIT NEAREST ENEMY?? IDK HOW MAN!!!
private void DeselectTarget()
{
newon = true;
target.renderer.material.color = Color.white;
target = null;
}
private void SelectTarget()
{
newon = false;
target.renderer.material.color = Color.red;
}
private void Attack() {
AttackandHP eh = (AttackandHP)target.GetComponent ("AttackandHP");
eh.AdjustCurrentHealth (-2);
}
}