Unity平滑相机缩放Rts游戏

时间:2017-09-10 02:45:33

标签: c# unity3d camera zoom

你好我有一个问题我的相机真的很好,我希望它放大和平滑我看了视频和论坛但我不知道我怎么能得到帮助这是所有相机的代码它的一个rts游戏以及它现在所做的就是你可以放大移动相机,鼠标位于屏幕的边缘。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RtsCamera : MonoBehaviour {

    public float scrollZone = 16;
    public float scrollSpeed = 5;
    public float zoomSensitivy = 15.0f;


    public float xMax = 8;
    public float xMin = 0;
    public float yMax = 8;
    public float yMin = 0;
    public float zMax = 8;
    public float zMin = 0;

    private Vector3 desiredPosition;
    private void Start()
    {
        desiredPosition = transform.position;
    }
    // Update is called once per frame
    void Update () {

       float x = 0, y = 0, z = 0;
       float speed = scrollZone * Time.deltaTime;

        if (Input.mousePosition.x < scrollZone)
            x -= speed;
        else if (Input.mousePosition.x > Screen.width - scrollZone)
            x += speed;

        if (Input.mousePosition.y < scrollZone)
            z -= speed;
        else if (Input.mousePosition.y > Screen.height - scrollZone)
            z += speed;


        y += Input.GetAxis("Mouse ScrollWheel")* zoomSensitivy;

        Vector3 move = new Vector3(x,y,z) + transform.position;
        move.x = Mathf.Clamp(move.x ,xMin ,xMax);
        move.y = Mathf.Clamp(move.y ,yMin ,yMax);
        move.z = Mathf.Clamp(move.z ,zMin ,zMax);
        desiredPosition = move;
        transform.position = Vector3.Lerp(transform.position, desiredPosition, 0.2f);

    }
}

0 个答案:

没有答案