_xiaofang/xiaofang/Assets/Script/Character/GodCamera.cs

94 lines
2.2 KiB
C#
Raw Normal View History

2024-10-21 10:08:49 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//<2F>ϵ<EFBFBD><CFB5>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public class GodCamera : MonoBehaviour
{
//<2F><><EFBFBD><EFBFBD>
Camera godCamera;
//<2F><>ʼλ<CABC><CEBB>
public Vector3 startPosition = new Vector3(0f, 0f, 0f);
//<2F><><EFBFBD><EFBFBD>x
public float maxPosX = 100f;
//<2F><>Сx
public float minPosX = -100f;
//<2F><><EFBFBD><EFBFBD>y
public float maxPosY = 50f;
//<2F><>Сy
public float minPosY = 10f;
//<2F><><EFBFBD><EFBFBD>z
public float maxPosZ = 100f;
//<2F><>Сz
public float minPosZ = -100f;
//<2F>ٶ<EFBFBD>
public float speed = 20;
//bool isGameStart = true;
// Start is called before the first frame update
void Start()
{
godCamera = transform.GetComponent<Camera>();
transform.position = startPosition;
godCamera.fieldOfView = 60;
}
// Update is called once per frame
void Update()
{
//<2F>ƶ<EFBFBD>
2024-11-19 16:30:22 +08:00
Move();
2024-10-21 10:08:49 +08:00
//<2F><>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>
2024-11-19 16:30:22 +08:00
ScaleView();
2024-10-21 10:08:49 +08:00
}
private void Move()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ʱ<EFBFBD><CAB1>,0<><30>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-19 16:30:22 +08:00
if (Input.GetMouseButton(0))
2024-10-21 10:08:49 +08:00
{
var x = Input.GetAxis("Mouse X");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮֡<D6A1><D6AE><EFBFBD><EFBFBD>ˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD>
var y = Input.GetAxis("Mouse Y");//<2F><>ֱ<EFBFBD><D6B1>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
if (x != 0 || y != 0)
{
2024-12-29 14:44:56 +08:00
Vector3 target = this.transform.position + new Vector3(-y, 0, x) * speed;
2024-10-21 10:08:49 +08:00
if (target.x > maxPosX || target.x < minPosX || target.z > maxPosZ || target.z < minPosZ)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD>򲻸<EFBFBD><F2B2BBB8><EFBFBD>λ<EFBFBD><CEBB>
return;
}
this.transform.position = Vector3.Lerp(this.transform.position, target, speed * Time.deltaTime);
}
}
}
private void ScaleView()
{
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ֵ
float mouseScrollWheel = Input.GetAxis("Mouse ScrollWheel");
if (mouseScrollWheel != 0)
{
godCamera.fieldOfView += mouseScrollWheel * speed;
if (godCamera.fieldOfView <= 38)
{
godCamera.fieldOfView = 38;
}
else if (godCamera.fieldOfView >= 95)
{
godCamera.fieldOfView = 95;
}
}
}
}