Now, it is time to make the script that makes our cube entity avoid the walls:
As usual, we first initialize our entity script with the default properties and draw GUI text in our OnGUI method. Let's take a look at the following code in the VehicleAvoidance.cs file:
using UnityEngine; using System.Collections; public class VehicleAvoidance : MonoBehaviour { public float speed = 20.0f; public float mass = 5.0f; public float force = 50.0f; public float minimumDistToAvoid = 20.0f; //Actual speed of the vehicle private float curSpeed; private Vector3 targetPoint; // Use this for initialization ...