网上浅尝了一下Unity
对C#一无所知。
教程里的脚本记录一下。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameralook : MonoBehaviour
{
private float xmove;
public float mousespeed;
public Transform player;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
//锁定鼠标位置
}
// Update is called once per frame
void Update()
{
float x, y;
x = Input.GetAxis("Mouse X")*mousespeed*Time.deltaTime;
//getaxis:axis是轴。
即Input输入mousex的值。
//getAxis("horizontal")对应键盘上面的左右箭头,当按下左或右箭头时触发
y = Input.GetAxis("Mouse Y")*mousespeed*Time.deltaTime;
//在unity世界里,y是数学里的z轴,垂直方向上面的变化。
即:x的数值=mousex的值*mouse速度(自定义的)*时间
player.Rotate(Vector3.up * x);
横向旋转。
vector3.up是一个已经定义的结构体
xmove = xmove - y;
xmove = Mathf.Clamp(xmove, -90, 90);
this.transform.localRotation = Quaternion.Euler(xmove, 0, 0);
//https://blog.csdn.net/loongkingwhat/article/details/80688618
//this是脚本所挂载的物体 即是这个相机
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)