I don’t know why but i seem to be having a problem with ray-casting, whats the problem with this code:
using UnityEngine;
using System.Collections;
public class BOT : MonoBehaviour {
public GameObject Enemy;
public GameObject EnemyBarrelEnd;
//public GameObject gun;
public int Health = 100;
public float Movecount;
// Update is called once per frame
public float RandomY;
public bool boolean = true;
public GameObject LaserBarrelEnd;
RaycastHit hit;
private float Distance;
private GameObject Soldier;
void Start()
{
}
void Update ()
{
Debug.DrawLine (transform.position, hit.point, Color.cyan);
//Distance=Vector3.Distance(Enemy,Soldier);
Ray MyRay = new Ray(LaserBarrelEnd.transform.position, Vector3.forward);
if(Physics.Raycast(MyRay, out hit,100)){
if (hit.collider.gameObject.tag == "soldier")
{
Shooting();
}
}
if (boolean)
{
Movecount=Random.Range(3f,5f);
boolean = false;
}
if (Health > 0)
{
RandomMove();
}
}
void RandomMove()
{
Movecount=Movecount-Time.deltaTime;
if (Movecount > 0)
{
Enemy.transform.position = Vector3.Lerp (Enemy.transform.position,EnemyBarrelEnd.transform.position,1f);
animation.Play("soldierRun");
}
if (Movecount<=0)
{
RandomTurn();
}
}
void RandomTurn()
{
RandomY =Random.Range(45f,360f);
Enemy.transform.Rotate(0,RandomY,0);
Movecount=Random.Range(3f,5f);
}
void Shooting()
{
Debug.Log("I see You");
}
}