更改帧数方法 在start()中修改参数 : Application.targetFrameRate = 10;
更改帧数方法 在start()中修改参数 : Application.targetFrameRate = 10;
Application.targetFrameRate = 多少(可以用来改变Update函数的调用次数,意为调整zheng'sh)
帧数最好停留在30-60,人眼无法感觉到卡顿
using System.Collections; using System.Collections.Generic; using UnityEngine; public class LunaController: MonoBehaviour { // Start is called before the first frame update void Start() { // Application.targetFrameRate = 30; } // Update is called once per frame void Update() { //获取玩家水平轴向输入值 float horizontal = Input.GetAxis("Horizontal"); //获取玩家垂直轴向输入值 float vertical = Input.GetAxis("Vertical"); // 在控制台输出当前的水平输入值,用于调试 Debug.Log(horizontal); // 在控制台输出当前的垂直输入值,用于调试 Debug.Log(vertical); // 获取当前物体的位置 Vector2 position = transform.position; // 根据水平输入移动物体的x坐标 position.x = position.x + 3f*horizontal*Time.deltaTime; // 根据垂直输入移动物体的y坐标 position.y = position.y + 3f*vertical*Time.deltaTime; // 更新物体的位置 transform.position = position; } }
如何设定游戏的帧率:
start方法中,使用代码
Application.targetFrameRate=10;
表示每秒10帧
Application.targetFrameRate = 60;