[Unity3D] Používanie DoTween na vytváranie efektov otočenia karty

Using Dotween Make Card Flip Effects



using System.Collections using System.Collections.Generic using UnityEngine using DG.Tweening//Do not forget to quote //card status, front, back public enum CardState { Front, Back } public class CardTurnOver : MonoBehaviour{ public GameObject mFront// card front public GameObject mBack// card back public CardState mCardState = CardState.Front//The current state of the card is front or back? public float mTime = 0.3f private bool isActive = false//true means that the flip is being executed and cannot be interrupted /// /// Initialize the card angle, according to mCardState /// public void Init() { if(mCardState==CardState.Front) { //If it starts from the front, rotate the back 90 degrees so that you can't see the back. mFront.transform.eulerAngles = Vector3.zero mBack.transform.eulerAngles = new Vector3(0, 90, 0) } else { //Start from the back, the same reason mFront.transform.eulerAngles = new Vector3(0, 90, 0) mBack.transform.eulerAngles = Vector3.zero } } private void Start() { Init() } /// /// Leave the interface called by the outside world /// public void StartBack() { if (isActive) return StartCoroutine(ToBack()) } /// /// Leave the interface called by the outside world /// public void StartFront() { if (isActive) return StartCoroutine(ToFront()) } /// /// flip to the back /// IEnumerator ToBack() { isActive = true mFront.transform.DORotate(new Vector3(0, 90, 0), mTime) for (float i = mTime i >= 0 i -= Time.deltaTime) yield return 0 mBack.transform.DORotate(new Vector3(0, 0, 0), mTime) isActive = false } /// /// flip to the front /// IEnumerator ToFront() { isActive = true mBack.transform.DORotate(new Vector3(0, 90, 0), mTime) for (float i = mTime i >= 0 i -= Time.deltaTime) yield return 0 mFront.transform.DORotate(new Vector3(0, 0, 0), mTime) isActive = false } }