- Home /
Question by
falloutguy923 · May 18, 2019 at 10:22 PM ·
c#transform.lookat
My transform.lookat is making my enemy invisible.
The enemy character i am wanting to implement in my game is acting weird when i put in the transform.lookat function, it makes the enemy invisible and the object still exists within the game, the z axis doesnt change and it doesnt disable the object.
public float speed;
private Transform target;
// Start is called before the first frame update
void Start()
{
target = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
// Update is called once per frame
void Update()
{
transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
transform.LookAt(target);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Bullet"))
{
Destroy(gameObject);
Destroy(other.gameObject);
}
}
Comment
Best Answer
Answer by unity_21erushbrook · May 18, 2019 at 11:46 PM
The sprite is probably just looking sideways. Think of looking at the thin edge of a piece of paper. It will appear to disappear. Just go into 3D mode whilst playing and see in the scene view what's going on. You can adjust the rotation there.
Thanks dude never would of thought of that, forgot the none 2d perspective was a thing
Your answer
![](https://koobas.hobune.stream/wayback/20220612201652im_/https://answers.unity.com/themes/thub/images/avi.jpg)