UGUI card flip effect

I saw an NGUI card flip effect on the Internet before. I tried it and it was OK, but there was no UGUI, so I made a UGUI. This is the blog address of that senior, if you want to see it, you can take a look: https://www.bobsong.net/486.html. UGUI interface settings: two pictures are put together (overlapping), one is positive and the other is negative. Create another button. The following are just the basic functions. If you have special requirements, you can adapt them yourself.

Let's step into the topic and see the code:

    private Quaternion T;
    private Quaternion V;
    public GameObject A;//Front
    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 make him rotate around itself
        //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,4f);
        if (A.transform.eulerAngles.y > 89 && A.transform.eulerAngles.y < 91)
        {

            B.transform.rotation = Quaternion.RotateTowards(B.transform.rotation, V,4f);
           
            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, 4f);
        if (B.transform.eulerAngles.y > 89 && B.transform.eulerAngles.y < 91)
        {

            A.transform.rotation = Quaternion.RotateTowards(A.transform.rotation, V, 4f);

            bol = true;
            //C.transform.GetComponent<Button>().enabled = true;
        }
       
     
    }

 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326681431&siteId=291194637