Hi i found this great waypoint script, but i would like to modify it a bit.
is it possible to put in if sentence in there like:
- if i click on an object,
- my current player position will be a waypoint,
- the clicked object will be a waypoint
- and my player will go to this spot,
- when the player reaches the waypoint the waypoints will destroy themselfs.
thanks in advance!
var waypoint : Transform[];
var speed : float = 50;
private var currentWaypoint : int = 0;
var loop : boolean = true;
var player : Transform;
private var character : CharacterController;
function Start ()
{
character = GetComponent(CharacterController);
}
function Update ()
{
if(currentWaypoint < waypoint.length)
{
var target : Vector3 = waypoint[currentWaypoint].position;
target.y = transform.position.y; // keep waypoint at character's height
var moveDirection : Vector3 = target - transform.position;
if(moveDirection.magnitude < 1)
{
transform.position = target; // force character to waypoint position
currentWaypoint++;
}
else
{
transform.LookAt(target);
character.Move(moveDirection.normalized * speed * Time.deltaTime);
}
}
else
{
if(loop)
{
currentWaypoint=0;
}
}
}