Hi peeps,
i'd like to share my modified version of "spin with mouse" script that comes with nGUI.
basically it now allows you to select which axis to spin on as well as the Delta direction X/Y (True/False) of the mouse.
using UnityEngine;
[AddComponentMenu("NGUI/Examples/Spin With Mouse")]
public class SpinWithMouse : MonoBehaviour
{
public enum Axis {
XAxis = 0,
YAxis = 1,
ZAxis = 2,
}
public Transform target;
public float speed = 1f;
public bool direction = true;
public Axis whichAxis = Axis.YAxis;
Transform mTrans;
void Start ()
{
mTrans = transform;
}
void OnDrag (Vector2 delta)
{
UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
float deltaval = delta.x;
Quaternion newRotation = Quaternion.Euler(0f, -0.5f * deltaval * speed, 0f);
if (direction) {
deltaval = delta.x;
} else {
deltaval = delta.y;
}
switch (whichAxis) {
case Axis.XAxis:
newRotation = Quaternion.Euler( -0.5f * deltaval * speed, 0f, 0f);
break;
case Axis.YAxis:
newRotation = Quaternion.Euler(0f, -0.5f * deltaval * speed, 0f);
break;
case Axis.ZAxis:
newRotation = Quaternion.Euler(0f, 0f, -0.5f * deltaval * speed);
break;
}
if (target != null) {
target.localRotation = newRotation * target.localRotation;
} else {
mTrans.localRotation = newRotation * mTrans.localRotation;
}
}
}
I know its not a huge change but i thought it might help someone.
Regards,
Lord Meshadieme