Advertisement
Guest User

Untitled

a guest
May 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ThirdPersonCamera : MonoBehaviour {
  6.  
  7.     public float sens = 10f;
  8.  
  9.     private Transform target;
  10.     private Vector3 offset;
  11.     private float rotX;
  12.     private float rotY;
  13.  
  14.     void Start () {
  15.         target = GameObject.Find ("Dummy").transform;
  16.         offset = transform.position - target.position;
  17.         print (target.position);
  18.         print (offset);
  19.     }
  20.    
  21.     void LateUpdate () {
  22.         if (Input.GetMouseButton (1)) {
  23.             float mouseX = Input.GetAxis ("Mouse X");
  24.             float mouseY = Input.GetAxis ("Mouse Y");
  25.  
  26.             if (mouseX != 0 && mouseY != 0) {
  27.                 print (mouseX + ", " + mouseY);
  28.  
  29.                 rotX += mouseX * sens * Time.deltaTime;
  30.                 rotY += mouseY * sens * Time.deltaTime;
  31.  
  32.                 Quaternion desiredRotation = Quaternion.Euler (-rotY, rotX, 0f);
  33.                 //transform.position = transform.position - desiredRotation * offset;
  34.                 transform.rotation = desiredRotation;
  35.             }
  36.         }
  37.         transform.LookAt(target.position + offset);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement