简体   繁体   English

优化用户输入的性能

[英]Optimizing the performance for user input

I'm developing a game and the main character's script goes a little like this:我正在开发一个游戏,主角的剧本有点像这样:

On the Update (loops every frame) method, I call there funtions在更新(每帧循环)方法上,我称之为函数

void Update(){

   InputManager();  //I set the Vector3 direction vector for the player's movement, and 

   Move();          //I make the player move according to the InputManager() direction vector. 
                    //I also set a boolean for every player state (eg. isMoving, isCrouching, isSliding, isGrounded)

   SpeedManager();  //Performes a Linear Interpolation (Mathf.Lerp) between the current speed and the final speed for every input given. 
                    //This includes the direction vector as well as sprinting and sliding

   AnimationManager();  //We check the booleans and apply an animation accordingly
}

The script works fine, but I'm having concerns about performance since the game drops from 400FPS to 260FPS when I press an input.该脚本运行良好,但我对性能感到担忧,因为当我按下输入时游戏从 400FPS 下降到 260FPS。 Also the game becomes unplayable if I select the player game object to which the script is attached to.如果我 select 玩家游戏 object 附加到该脚本,则游戏也变得无法玩。

What's your two cents on this?你的两分钱是多少?

Use the Unity Profiler to see where your time is being spent.使用 Unity Profiler 查看您的时间都花在了哪里。 That's the best way to tackle performance problems.这是解决性能问题的最佳方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM