using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; public class TYY : MonoBehaviour { //videoPlayer.url = "https://edu-xnfz.educoder.net/Test/Hejidong/ZNHome/c9.mp4"; public GameObject mubu; bool curState = false; public Vector3 startPos; public float Speed; Vector3 birthPlace; private void Awake() { birthPlace = transform.position; } public void swap() { if (curState) { curState = false; mubu.GetComponent().Stop(); StartCoroutine(Run(birthPlace)); } else { curState = true; StartCoroutine(Run(startPos)); TaskCenter.GetInstance().FinishTask(7); } } 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) { if (curState==true) { mubu.GetComponent().Play(); } break; } } } }