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; } } } }