using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class BlackController : UnitySingleton { public float moveDuration = 0.5f; public float waitDuration = 0.5f; public bool AllBlack = false; private void Start() { DontDestroyOnLoad(transform.parent.gameObject); } private void Update() { transform.parent.transform.position = Camera.main.transform.position + new Vector3(0,0,1f); } //呼出从左到右的黑幕 public void Trans(){ StartCoroutine(ComeInCoroutine()); } private IEnumerator ComeInCoroutine(){ //移动黑幕遮住屏幕 transform.DOLocalMoveX(0f, moveDuration); //等待移动结束,并等待预留的加载时间 yield return new WaitForSeconds(moveDuration); AllBlack = true; yield return new WaitForSeconds(waitDuration); //此时屏幕全黑,并已等待完加载时间 //揭开黑幕 AllBlack = false; transform.DOLocalMoveX(-170f, moveDuration); //等待黑幕运动结束 yield return new WaitForSeconds(moveDuration); //恢复黑幕位置 transform.localPosition = new Vector3(170f, 0f, 0); } }