当鼠标越过边界时,我正在为屏幕平移创建代码。代码有效,但无论浮动速度值如何,它都以相同的速度滚动(我已经尝试了很大的值,例如3000000只是为了检查),从我在线检查我正确使用Time.deltaTime,所以我不知道发生了什么。
public static bool isOnMap = true;
public GameObject CameraObject;
public int Boundary = 50; // distance from edge scrolling starts
public float speed = 1f;
private int theScreenWidth;
private int theScreenHeight;
public static float MapWidth;
public static float MapHeight;
public float Velocity ()
{
float velocity;
velocity = speed * Time.smoothDeltaTime;
Debug.Log(velocity);
return velocity;
}
void Start()
{
theScreenWidth = Screen.width;
theScreenHeight = Screen.height;
}
void Update()
{
//mouse
#region
if (isOnMap && Input.mousePosition.x > theScreenWidth - Boundary)
{
if (transform.position.x >= MapWidth)
{
return;
}
else
{
transform.position = new Vector3(transform.position.x + Velocity(), transform.position.y, transform.position.z);
}
}
if (isOnMap && Input.mousePosition.x < 0 + Boundary)
{
if (transform.position.x <= 5)
{
return;
}
else
{
transform.position = new Vector3(transform.position.x - Velocity(), transform.position.y, transform.position.z);
}
}
if (isOnMap && Input.mousePosition.y > theScreenHeight - Boundary)
{
if (transform.position.y >= MapHeight + 5)
{
return;
}
else
{
transform.position = new Vector3(transform.position.x, transform.position.y + Velocity(), transform.position.z);
}
}
if (isOnMap && Input.mousePosition.y < 0 + Boundary)
{
if (transform.position.y <= 0)
{
return;
}
else
{
transform.position = new Vector3(transform.position.x, transform.position.y - Velocity(), transform.position.z);
}
}
}
答案 0 :(得分:0)
如下更改。同时更改speed
1
以更改总体速度。
public float Velocity ()
{
return speed * Time.deltaTime;
}