I’m trying to create an AI that goes to the player, I have a script that is supposed to move the zombie to the player but the zombie didn’t move and when I move to the zombie unity freezes, here’s my script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Deformed : MonoBehaviour {
Rigidbody2D rb2D;
Rigidbody2D playerRb2D;
Transform trans;
Transform playerTrans;
public float Distancebetween;
public GameObject player;
void Start () {
rb2D = gameObject.GetComponent<Rigidbody2D> ();
trans = gameObject.GetComponent<Transform> ();
playerTrans = player.GetComponent<Transform> ();
playerRb2D = player.GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
Distancebetween = playerTrans.position.x - trans.position.x;
while (Distancebetween > 0) {
rb2D.AddForce (Vector2.right * playerRb2D.velocity.x);
}
}
}