Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ThirdPersonCamera : MonoBehaviour {
- public float sens = 10f;
- private Transform target;
- private Vector3 offset;
- private float rotX;
- private float rotY;
- void Start () {
- target = GameObject.Find ("Dummy").transform;
- offset = transform.position - target.position;
- print (target.position);
- print (offset);
- }
- void LateUpdate () {
- if (Input.GetMouseButton (1)) {
- float mouseX = Input.GetAxis ("Mouse X");
- float mouseY = Input.GetAxis ("Mouse Y");
- if (mouseX != 0 && mouseY != 0) {
- print (mouseX + ", " + mouseY);
- rotX += mouseX * sens * Time.deltaTime;
- rotY += mouseY * sens * Time.deltaTime;
- Quaternion desiredRotation = Quaternion.Euler (-rotY, rotX, 0f);
- //transform.position = transform.position - desiredRotation * offset;
- transform.rotation = desiredRotation;
- }
- }
- transform.LookAt(target.position + offset);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement