如何控制屏幕(摄像机)移动

来源:互联网 发布:项目管理 源码 编辑:程序博客网 时间:2024/06/07 23:11
using UnityEngine;using System.Collections;public class ScrenSlip : MonoBehaviour {    // Use this for initialization    void Start()    {    }    // Update is called once per frame    void Update()    {        Vector3 v1 = Camera.main.ScreenToViewportPoint(Input.mousePosition);//将摄像机屏幕坐标转换为        if (v1.x >0.9f)        {            transform.Translate(Vector3.left* Time.deltaTime * 3, Space.World);//当鼠标在右侧时,使相机向右移动(这里是left是因为转换之后摄像机是反的属于正常)        }        if (v1.x <0.1f)        {            transform.Translate(Vector3.right * Time.deltaTime * 3, Space.World);//当鼠标在左侧时,使相机向左移动        }        if (v1.y >0.9f)        {            transform.Translate(Vector3.back * Time.deltaTime * 3, Space.World);//当鼠标在上侧时,使相机向上移动        }        if (v1.y <0.1f)        {            transform.Translate(Vector3.forward * Time.deltaTime * 3, Space.World);//当鼠标在下侧时,使相机向下移动        }    }}
阅读全文
0 0
原创粉丝点击