- Home /
How to perform counter-clockwise page turn effect, based on existing clockwise code?
Hello, guys! I'm trying to create page flip effect in Unity, using UI system. I've found such code:
using UnityEngine;
using System.Collections;
public class CurlEf : MonoBehaviour {
public Transform _Front;
public Transform _Mask;
public Transform _GradOutter;
public Vector3 _Pos;
void Start()
{
_Pos = transform.position;
}
void LateUpdate()
{
// transform.position = _Pos; // To fix position of back image
// transform.eulerAngles = Vector3.zero;
Vector3 pos = _Front.localPosition;
float theta = Mathf.Atan2 (pos.y, pos.x) * 180.0f/ Mathf.PI; // angle between X and Y?
if (theta <= 0.0f || theta >= 90.0f) return;
float deg = -(90.0f - theta) * 2.0f;
_Front.eulerAngles = new Vector3(0.0f, 0.0f, deg);
// Move mask to "cut" front and back images
_Mask.position = (transform.position + _Front.position) * 0.5f;
_Mask.eulerAngles = new Vector3(0.0f, 0.0f, deg*0.5f);
// Move gradient to create effect of volume
_GradOutter.position = _Mask.position;
_GradOutter.eulerAngles = new Vector3(0.0f, 0.0f, deg * 0.5f + 90.0f);
// Next to make immobilize back image
transform.position = _Pos; // To fix position of back image
transform.eulerAngles = Vector3.zero;
}
}
It uses Mask to perform flip effect and works perfectly, but works only in a clockwise direction (kind of turn page back to prev page). What I'm trying to do is to perform a counter-clockwise animation, based on this code. But I don't understand how to do this.
Check this video for detailed view https://www.youtube.com/watch?v=CUW3fGEK9as and this link for whole project: http://gnupart.tistory.com/entry/Unity3D-Simple-Page-Curl-Effect
Could you please, help me? At least, could someone explain what is theta and how to calculate deg for my purposes?
Your answer
![](https://koobas.hobune.stream/wayback/20220612051659im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Poke hole in UI Image? 1 Answer
UI mask with a 3D object 1 Answer
Trying to move slider based off percentage of screen 1 Answer
Detect if UI element is visible 0 Answers
Canvas is flipping, 2D game 0 Answers