- Home /
Question by
Mutaz · Jan 26, 2014 at 01:59 AM ·
touchmouseorbit
touch mouseorbit dosent work
Hi guys, I need your help, I have a problem and I cant solve it right now, so anyone can help me ? ok this is my problem, I have the mouseorbit script but it dosent work when I use the touch screen on the android, and this is the script:
var rotJoy : GameObject;
var target : Transform;
var distance = 10.0;
var xSpeed = 250.0;
var ySpeed = 120.0;
var yMinLimit = -20;
var yMaxLimit = 80;
private var x = 0.0;
private var y = 0.0;
@AddComponentMenu("Camera-Control/Mouse Orbit")
partial class MouseOrbit { }
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
function Update(){
target = GameObject.FindWithTag("Player").transform;
}
function LateUpdate () {
if (target) {
if(Application.platform == RuntimePlatform.Android)
{
var other : Joystick;
other = rotJoy.GetComponent("Joystick");
var tmpRotJoyX = other.position.x * 0.6f;
x += Time.deltaTime * tmpRotJoyX * xSpeed;
var tmpRotJoyY = other.position.y * 0.4f;
y -= Time.deltaTime * tmpRotJoyY * ySpeed;
y = ClampAngle(y, yMinLimit, yMaxLimit);
}
else
{
x += Time.deltaTime * Input.GetAxis("Mouse X") * xSpeed;
y -= Time.deltaTime * Input.GetAxis("Mouse Y") * ySpeed;
y = ClampAngle(y, yMinLimit, yMaxLimit);
}
var rotation = Quaternion.EulerAngles(y * Mathf.Deg2Rad, x * Mathf.Deg2Rad, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
Comment
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
[Unity Editor] Emulate Touch Input - Still Asking 12/10 1 Answer
Touch command for GUIText on Android? OnMouseDown() for Android? 1 Answer
Make Swipe Detection Longer? 0 Answers
Touch Input, user can touch across the screen, not wanted 1 Answer