Advertisement
Muk99

CameraRotate

Jan 9th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [AddComponentMenu("Camera/Camera Rotate")]
  5. [RequireComponent (typeof (AccelerometerInputBehaviour))]
  6.  
  7. public class CameraRotate : MonoBehaviour {
  8.    
  9.     public JoystickBehaviour joystick;
  10.     public float rotateSpeed = 80.0f;
  11.  
  12.     private AccelerometerInputBehaviour accel;
  13.     private Quaternion startRotation;
  14.     private Quaternion startRotationInvert;
  15.  
  16.     void Start () {
  17.         startRotation = transform.localRotation;
  18.         startRotationInvert = transform.localRotation;
  19.         startRotationInvert.y += 180;
  20.  
  21.         accel = GetComponent <AccelerometerInputBehaviour> ();
  22.     }
  23.  
  24.     void Update () {
  25.         if (joystick.output.y > 0 || Input.GetAxis ("Vertical") > 0)
  26.             transform.localRotation = startRotation;
  27.  
  28.         else if (joystick.output.y < 0 || Input.GetAxis ("Vertical") < 0)
  29.             transform.localRotation = startRotationInvert;
  30.  
  31.         else
  32.             transform.Rotate (Vector3.up, rotateSpeed * accel.output * Time.deltaTime);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement