Ai script(rotation) causes game to crash


for my first attemps lerning unity and building my first game, Im using the script bellow. For some reason the game crashes once the ai gets closer to my player. I found out removing the “transform.Rotate” line(19) prevents the game from crashing. But of course the script isnt doing its job anymore once i removed this(ai keeps cricling, looks funny but its not what I want). Ive already spent about an hour trying to solve the problem but I cant find it… Maybe somone of you nice guys can help me with this

	using UnityEngine;
	using System.Collections;

	public class EnemyController : MonoBehaviour {

		public Transform target;//set target from inspector instead of looking in Update
		public float speed = 3f;

		void Start () {


		void Update(){

			//rotate to look at the player
			transform.Rotate(new Vector3(0,-90,0),Space.Self);//correcting the original rotation

			//move towards the player
			if (Vector3.Distance(transform.position,target.position)>1f){//move if distance from target is greater than 1
				transform.Translate(new Vector3(speed* Time.deltaTime,0,0) );



There is nothing wrong with your script. Works fine on my end.

A few questions:

  • What version of Unity do you use?
  • Is it your intention to move the object sideways?