Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ballMovement : MonoBehaviour {
- private Rigidbody ball_rb;
- public float _sensitivity;
- private Vector3 _mouseReference;
- private Vector3 _mouseOffset;
- private Vector3 _rotation;
- private bool _isRotating;
- // Use this for initialization
- void Start () {
- ball_rb = GetComponent<Rigidbody>();
- _sensitivity = 0.4f;
- _rotation = Vector3.zero;
- }
- // Update is called once per frame
- void Update () {
- CameraMovement();
- }
- void CameraMovement()
- {
- if (_isRotating)
- {
- // offset
- _mouseOffset = (Input.mousePosition - _mouseReference);
- // apply rotation
- _rotation.y = -(_mouseOffset.x + _mouseOffset.y) * _sensitivity;
- // rotate
- transform.Rotate(_rotation);
- // store mouse
- _mouseReference = Input.mousePosition;
- }
- if (Input.GetMouseButtonDown(1))
- {
- // rotating flag
- _isRotating = true;
- // store mouse
- _mouseReference = Input.mousePosition;
- }
- else if(Input.GetMouseButtonUp(1))
- {
- // rotating flag
- _isRotating = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement