You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SaoDiJiQi : MonoBehaviour
{
public enum State {
work,
unwork
}
public bool StateOfJQR;
State curState;
public float Speed;
Vector3 birthPlace;
public Transform[] points;
[SerializeField]
int curPointIndex;
private void Awake()
{
curState = State.unwork;
birthPlace = transform.position;
curPointIndex = 0;
StateOfJQR = false;
}
private void Update()
{
switch (curState) {
case State.work:
Vector3 dir = (points[curPointIndex].position - transform.position).normalized;
transform.position+=(dir*Speed*Time.deltaTime);
IsArrive();
break;
case State.unwork:
//Vector3 Dir = (birthPlace - transform.position).normalized;
//transform.position += (Dir * Speed * Time.deltaTime);
break;
}
}
void IsArrive() {
if (Vector3.Distance(transform.position, points[curPointIndex].position) <= 0.05f) {
if (curPointIndex == points.Length - 1)
{
curPointIndex = 0;
return;
}
curPointIndex++;
}
}
public void updateState() {
if (curState == State.work)
{
curState = State.unwork;
//curPointIndex = 0;
}
else{
TaskCenter.GetInstance().FinishTask(1);
curState = State.work;
}
}
public void JQR()
{
if (StateOfJQR)
{
StateOfJQR = false;
updateState();
}
else
{
StateOfJQR = true;
updateState();
}
}
}