当前位置:网站首页>Unity card flipping effect

Unity card flipping effect

2022-07-05 04:56:00 Meteor spot

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fanzhuan : MonoBehaviour
{
    private Quaternion T;
    private Quaternion V;
    public GameObject A;// positive    
    public GameObject B;// Back     //
   // public GameObject C;
    private bool bol = true;
    void Start()
    {
        B.transform.rotation = Quaternion.Euler(0, 90, 0);
    }
    public void Init()
    {
        A.transform.rotation = Quaternion.Euler(0, 0, 0);
        B.transform.rotation = Quaternion.Euler(0, 90, 0);
    }
    void Update()
    {             
        // The following two lines are for him to rotate around himself        //
       // A.transform.Rotate(new Vector3(0, 90 * Time.deltaTime * 2.5f, 0));
        // 
        //A.transform.Rotate(Vector3.down,3);
    }
    public void BtnClick()
    {
       
        if (bol)
        {
            // Init();            
            InvokeRepeating("BE", 0, 0.02f);
            CancelInvoke("BD");
        }
        else
        {
            //Init();
            InvokeRepeating("BD", 0.5f, 0.02f);
            CancelInvoke("BE");
        }
    }
    private void BE()
    {
        // C.transform.GetComponent<Button>().enabled = false;
        T = Quaternion.Euler(0, 90, 0);
        V = Quaternion.Euler(0, 0, 0);
        A.transform.rotation = Quaternion.RotateTowards(A.transform.rotation, T,6f);
        if (A.transform.eulerAngles.y > 89 && A.transform.eulerAngles.y < 91)
        {
            B.transform.rotation = Quaternion.RotateTowards(B.transform.rotation, V,6f);
            bol = false;
            //  C.transform.GetComponent<Button>().enabled = true;
        }
    }
    private void BD()
    {
        // Return action       
        // C.transform.GetComponent<Button>().enabled = false; 
        T = Quaternion.Euler(0, 90, 0);
        V = Quaternion.Euler(0, 0, 0);
        B.transform.rotation = Quaternion.RotateTowards(B.transform.rotation, T, 6f);
        if (B.transform.eulerAngles.y > 89 && B.transform.eulerAngles.y < 91)
        {
            // Add this judgment because it is written 90 degree , But it can't be directly 90 Degree integer , So I added such a judgment  
            A.transform.rotation = Quaternion.RotateTowards(A.transform.rotation, V, 6f);
            bol = true;
            //C.transform.GetComponent<Button>().enabled = true;
        }
    }


}
 

原网站

版权声明
本文为[Meteor spot]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140625237785.html