when enemy ai chase player enemy turns invisible
when the enemy is chasing the player it turns invisible but it's Collider is still there any help ?
here is the code :
using UnityEngine;
using System.Collections;
public class BossEi : MonoBehaviour {
public Transform target;
public float moveSpeed;
public int minRange;
public bool follow;
public GameObject Player;
// Use this for initialization
void Start () {
Player = GameObject.FindGameObjectWithTag("Player");
GameObject go = GameObject.FindGameObjectWithTag ("Player");
target = go.transform;
}
// Update is called once per frame
void Update () {
if (Vector3.Distance (transform.position, target.position) < minRange)
follow = true;
if (follow) {
transform.LookAt (target);
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
}
}
and a note that this is a 2d game
Comment
Start() defines both Player and "go" by findingwithtag Player - see no need for both.
Update does nothing that you report happens, so you are observing other code behaviour or your camera culling is filtering - something outside this code is happening. follow will be true forever once set (possibly intended).
l made the code for this to this
using UnityEngine;
using System.Collections;
public class BossEi : $$anonymous$$onoBehaviour {
public Transform target;
public float moveSpeed;
public int $$anonymous$$Range;
public bool follow;
public GameObject Player;
// Use this for initialization
void Start () {
Player = GameObject.FindGameObjectWithTag("Player");
target = Player.transform;
}
// Update is called once per frame
void Update () {
if (Vector2.Distance (transform.position, target.position) < $$anonymous$$Range){
follow = true;
}
if (follow) {
transform.LookAt (target);
transform.Translate(Vector2.left * moveSpeed * Time.deltaTime);
}
}
}
and it works at bit better but the enemy is rotating in 3d and this is a 2d game so it acts wiard any way l can fix this ?
Your answer
![](https://koobas.hobune.stream/wayback/20220612002601im_/https://answers.unity.com/themes/thub/images/avi.jpg)