43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
public class MoveFollow : MonoBehaviour
|
|
{
|
|
public float speed;
|
|
public Transform path;
|
|
Transform[] pathPoints;
|
|
int index;
|
|
|
|
Vector3 mouseDir;
|
|
|
|
void Start()
|
|
{
|
|
pathPoints = path.GetComponentsInChildren<Transform>();
|
|
pathPoints[0] = transform;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if(Vector3.Distance(transform.position, pathPoints[index].position) < 1f)
|
|
{
|
|
++index;
|
|
if(index >= pathPoints.Length)
|
|
{
|
|
index = 0;
|
|
}
|
|
}
|
|
|
|
transform.Translate((pathPoints[index].position - transform.position) * Time.deltaTime * speed);
|
|
|
|
if(Input.GetMouseButton(1))
|
|
{
|
|
mouseDir.x -= Input.GetAxis("Mouse Y") * Time.deltaTime * 800;
|
|
mouseDir.y += Input.GetAxis("Mouse X") * Time.deltaTime * 800;
|
|
|
|
Camera.main.transform.localRotation = Quaternion.Euler(mouseDir);
|
|
}
|
|
}
|
|
}
|