41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlayerScript : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
public Vector3 offset;
|
|
public float sensitivity = 3; // ÷óâñòâèòåëüíîñòü ìûøêè
|
|
public float limit = 80; // îãðàíè÷åíèå âðàùåíèÿ ïî Y
|
|
public float zoom = 0.25f; // ÷óâñòâèòåëüíîñòü ïðè óâåëè÷åíèè, êîëåñèêîì ìûøêè
|
|
public float zoomMax = 10; // ìàêñ. óâåëè÷åíèå
|
|
public float zoomMin = 3; // ìèí. óâåëè÷åíèå
|
|
private float X, Y;
|
|
|
|
void Start()
|
|
{
|
|
limit = Mathf.Abs(limit);
|
|
if (limit > 90) limit = 90;
|
|
offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax) / 2);
|
|
transform.position = target.position + offset;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetAxis("Mouse ScrollWheel") > 0) offset.z += zoom;
|
|
else if (Input.GetAxis("Mouse ScrollWheel") < 0) offset.z -= zoom;
|
|
offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
|
|
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
X = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivity;
|
|
Y += Input.GetAxis("Mouse Y") * sensitivity;
|
|
Y = Mathf.Clamp(Y, -limit, limit);
|
|
transform.localEulerAngles = new Vector3(-Y, X, 0);
|
|
}
|
|
transform.position = transform.localRotation * offset + target.position;
|
|
|
|
}
|
|
}
|