using DG.Tweening; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; public class snailRider : MonoBehaviour { public Image palye; public GameObject obj; public List LightSprite; public GameObject startingPoint; public GameObject end; public bool is_victory = false;//这只蜗牛是否在本回合比赛胜利 public bool is_die = false;//这个蜗牛死了没 float offset = 0; public Animator animator; public Sequence mySequence = DOTween.Sequence(); // Start is called before the first frame update async void Start() { //startMove(); //while (true) //{ // if (LightSprite == null) return; // foreach (Sprite sprite in LightSprite) // { // if (palye != null) // { // palye.sprite = sprite; // await Task.Delay(50); // } // } //} } private void OnDestroy() { LightSprite = null; } public void MoveOrStand() { } public void killsnail() { obj.SetActive(!is_die); } public void startMove() { //palye.enabled = !is_die; animator.SetInteger("State",1);//切换为移动动画 float suiji = 0;//时间时间 if (is_victory) { suiji = UnityEngine.Random.Range(5, 7); } else { suiji = UnityEngine.Random.Range(8, 10); } transform.DOMoveX(end.transform.position.x, suiji).SetEase(Ease.Linear).OnComplete(()=> { animator.SetInteger("State", 0); Debug.Log("动画完成,切换为待机动画"); AllManeger.instance.WinNum--; if (AllManeger.instance.WinNum <= 0) { AllManeger.instance.StopAllSanil(); } }) //切换为待机动画 ; mySequence.OnKill(()=> { AllManeger.instance.snailMoveNum++; }); } public void returnStart() { //Debug.Log(transform.name); //Debug.Log(transform.position); mySequence.Kill(); // 停止并销毁动画 transform.position=startingPoint.transform.position; animator.SetInteger("State", 0); //Debug.Log(startingPoint.transform.position); //Debug.Log(transform.position); } private void Update() { offset = Mathf.Lerp(offset, 0, 1f * Time.deltaTime); obj.transform.localPosition = Vector3.Lerp(obj.transform.localPosition, new Vector3(offset, 0, 0), 1f * Time.deltaTime); } async void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.GetComponent()!=null) { if (other.gameObject.GetComponent().mode == snailRiderItem.Mode.accelerate) { offset = 500; } else if (other.gameObject.GetComponent().mode == snailRiderItem.Mode.slowDown) { offset = -500; } Destroy(other.gameObject); } else//碰到终点线 { Debug.Log("碰到"); animator.SetInteger("State", 0); } } }