我只是想为android游戏创建一个摄像头,你可以在x轴上缩放和移动,我想为这款相机设定一个限制。例如,当orthographicSize大于变量max_zoom或小于变量min_zoom时,我希望相机停止缩放。
问题是,如果用户缩放得非常快,更新函数更新的速度不够快,例如,即使我的orthographicSize变量为1,min_zoom也等于0.995。
if(GetComponent<Camera> ().orthographicSize > min_zoom && GetComponent<Camera> ().orthographicSize < max_zoom) {
// .. change the orthographic size based on the change in distance between the touches.
GetComponent<Camera> ().orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;
// Make sure the orthographic size never drops below zero.
GetComponent<Camera> ().orthographicSize = Mathf.Max(GetComponent<Camera> ().orthographicSize, 0.1f);
}所以问题是用户不能放大。
发布于 2015-06-02 10:13:02
好的,我终于找到了变焦的解决方案。我只是删除了这个条件,在脚本的末尾,我使用Mathf.clamp在我的min_zoom和max_zoom之间设置了orthographicSize。最后一个问题(但不是缩放)是,我不能在右边和左边设定一个固定的限制,因为当你缩放时,限制的坐标会发生变化,但这是另一个主题。不管怎样,谢谢你的回答。
发布于 2015-05-31 13:52:05
为什么要为每个函数调用GetComponent<Camera>(),您可以调用start --它就足够了。
Camera cam;
void Start ()
{
cam = GetComponent<Camera> ();
}
// Update is called once per frame
void Update ()
{
if( cam.orthographicSize > min_zoom && cam.orthographicSize < max_zoom)
{
cam.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;
cam.orthographicSize = Mathf.Max(cam.orthographicSize, 0.1f);
}
}https://stackoverflow.com/questions/30554517
复制相似问题