Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class WayPointTraverser : MonoBehaviour {
- public Transform[] waypoints;
- public Transform mainCamera;
- public float speed = 3;
- public float startRotationDistance = 2;
- public float rotationSpeed = 5;
- private Quaternion currentDesiredRotation;
- void Start () {
- StartCoroutine(MoveThroughWaypoints());
- }
- private IEnumerator MoveThroughWaypoints()
- {
- int currentWaypoint = 0;
- currentDesiredRotation = waypoints[currentWaypoint].rotation;
- while (true)
- {
- mainCamera.position = Vector3.MoveTowards(mainCamera.position, waypoints[currentWaypoint].position, speed * Time.deltaTime);
- mainCamera.rotation = Quaternion.Lerp(mainCamera.rotation, currentDesiredRotation, rotationSpeed * Time.deltaTime);
- if ((mainCamera.position - waypoints[currentWaypoint].position).magnitude <= startRotationDistance)
- {
- currentDesiredRotation = waypoints[currentWaypoint].rotation;
- }
- if (mainCamera.position == waypoints[currentWaypoint].position)
- {
- currentWaypoint = (currentWaypoint + 1) % waypoints.Length;
- }
- yield return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement