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 FollowCamera : MonoBehaviour
- {
- [SerializeField] Transform Player;
- public Camera MainCamera;
- private Vector3 MousePosition;
- private Vector3 newPlayerPosition;
- private float offsetX;
- private float offsetY;
- void Start()
- {
- offsetX = 0f;
- offsetY = 0f;
- }
- // Update is called once per frame
- void Update()
- {
- //Rotate Camera <->
- if (Input.GetMouseButton(1))
- {
- if (Input.GetMouseButtonDown(1))
- {
- MousePosition = Input.mousePosition;
- }
- if (MousePosition[0] != Input.mousePosition[0])
- {
- transform.Rotate(0, Input.mousePosition[0] - MousePosition[0], 0, Space.Self);
- }
- MousePosition = Input.mousePosition;
- }
- // Move Camera
- if (Input.GetMouseButton(2))
- {
- if(Input.GetMouseButtonDown(2))
- {
- MousePosition = Input.mousePosition;
- Debug.Log(Player.position);
- }
- // Up & Down
- if(MousePosition[1] != Input.mousePosition[1])
- {
- offsetY += (Input.mousePosition[1] - MousePosition[1])/2;
- Debug.Log(offsetY);
- }
- // Left & Right
- if(MousePosition[0] != Input.mousePosition[0])
- {
- offsetX += (MousePosition[0] - Input.mousePosition[0])/4;
- Debug.Log(offsetX);
- }
- MousePosition = Input.mousePosition;
- }
- //Zoom Camera In/Out
- if (Input.GetAxis("Mouse ScrollWheel") != 0f)
- {
- MainCamera.transform.Translate(0,0,2f*Input.GetAxis("Mouse ScrollWheel"));
- }
- //Follow The Player
- newPlayerPosition = Player.position;
- newPlayerPosition[0] += offsetX;
- newPlayerPosition[1] += offsetY;
- transform.position = newPlayerPosition;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement