This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using UnityEngine;
/// <summary>
/// Attaching this script to an object will make it turn as it gets closer to left/right edges of the screen.
/// Look at how it's used in Example 6.
/// </summary>
[AddComponentMenu("NGUI/Examples/Window Auto-Yaw")]
public class WindowAutoYaw : MonoBehaviour
{
public int updateOrder = 0;
public Camera uiCamera;
public float yawAmount = 20f;
Transform mTrans;
void OnDisable ()
{
mTrans.localRotation = Quaternion.identity;
}
void OnEnable ()
{
if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer);
mTrans = transform;
}
void Update ()
{
if (uiCamera != null)
{
Vector3 pos = uiCamera.WorldToViewportPoint(mTrans.position);
mTrans.localRotation = Quaternion.Euler(0f, (pos.x * 2f - 1f) * yawAmount, 0f);
}
}
}