我正在努力搞乱一分钱像素演示。
见到这里: https://www.youtube.com/watch?v=tDX2ChhntD8
可在此处下载: https://oc.unity3d.com/index.php/s/nS02rplRWJN1d6C
当我左右长距离跑步时,似乎经常口吃。这是一个视频: https://youtu.be/GFtjfI1cje8
相机的代码在这里:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public GameObject player;
public Camera main_camera;
void Update()
{
if (player != null)
{
float player_x = player.transform.position.x;
float player_y = player.transform.position.y;
float rounded_x = RoundToNearestPixel(player_x);
float rounded_y = RoundToNearestPixel(player_y);
Vector3 new_pos = new Vector3(rounded_x, rounded_y, -10.0f); // this is 2d, so my camera is that far from the screen.
main_camera.transform.position = new_pos;
}
}
public float pixelToUnits = 40f;
public float RoundToNearestPixel(float unityUnits)
{
float valueInPixels = unityUnits * pixelToUnits;
valueInPixels = Mathf.Round(valueInPixels);
float roundedUnityUnits = valueInPixels * (1 / pixelToUnits);
return roundedUnityUnits;
}
}