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.

51 lines
1.1 KiB

2 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Window : MonoBehaviour
{
public Vector3 startPos;
public float Speed;
Vector3 birthPlace;
bool curState;
private void Awake()
{
birthPlace = transform.position;
curState = false;
}
public void open() {
StartCoroutine(Run(startPos));
print("开窗");
}
public void close() {
StartCoroutine(Run(birthPlace));
}
public void Swap() {
if (curState)
{
curState = false;
close();
}
else {
TaskCenter.GetInstance().FinishTask(3);
curState = true;
open();
}
}
IEnumerator Run(Vector3 tragetpos)
{
Vector3 dir = tragetpos - transform.position;
while (true)
{
yield return new WaitForEndOfFrame();
transform.position += dir * Speed * Time.deltaTime;
if (Vector3.Distance(tragetpos, transform.position) <= 0.05f)
{
break;
}
}
}
}