Hello everyone, seems I’ve got a bit of a problem.
I’m trying to make it so when the player enters a trigger on an enemy, the enemy will look at the player and go towards him, but I keep getting the error
Here’s my code
using UnityEngine;
using System.Collections;
public class AutoAI : MonoBehaviour {
public float speed = 20;
public float rotateSpeed = 10;
public float leftRight = 3;
public float inFront = 7;
private int direction = 1;
public bool isViewed = false;
public float player : tag;
// Use this for initialization
void Start () {
}
void OnTriggerEnter (Collider collision)
{
if (Collision.GameObject.FindGameObjectsWithTag(player))
{
isViewed = true;
}
if (isViewed)
{
Transform.LookAt(player);
}
}
// Update is called once per frame
void Update () {
StartCoroutine(PickDirection());
if (!Physics.Raycast(Transform.position, Transform.forward, inFront))
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
else{
if (Physics.Raycast(transform.position, -transform.right, leftRight))
{
direction = -1;
}
else if (Physics.Raycast(transform.position, transform.right, leftRight))
{
direction = 1;
}
}
transform.Rotate(Vector3.up, 90 * rotateSpeed * Time.smoothDeltaTime * direction);
}
}
Any help is greatly appreciated.
plus on top of that your free to use the code if you need it ![]()