Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Walk : MonoBehaviour {
- public GameObject[] Waypoints;
- public int currTarget = 0;
- public int waypointLength;
- public float speed = 3;
- public float changeTargetValue = 1;
- public float rotationSpeed = 9;
- public float time= 0;
- void Start ()
- {
- waypointLength = Waypoints.Length;
- }
- void Update ()
- {
- time += Time.deltaTime;
- if (time > 0.5f)
- {
- if (currTarget < waypointLength)
- {
- var lookPos = Waypoints[currTarget].transform.position - transform.position;
- lookPos.y = 0;
- var rotation = Quaternion.LookRotation(lookPos);
- transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);
- transform.Translate(Vector3.forward * Time.deltaTime * speed);
- if (Vector3.Distance(transform.position, Waypoints[currTarget].transform.position) < changeTargetValue)
- {
- currTarget++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement