[Unity] unity2d 怎么以鼠标位置为中心放大视角

查看:401 |回复:4 | 2021-2-23 10:16:39

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 源数之力 于 2021-3-2 14:42 编辑

unity2d 游戏,怎么像unity 编辑器里那样,平滑地放大视角,保持鼠标一直在目标点。
2021-2-23 10:16:39  
 赞 赞 0

使用道具 登录

4个回答,把该问题分享到群,邀请大神一起回答。
2#
如过你是用的透视摄像机的话;
调整你Camera的Filed of View 属性,那个Slider你左右拖一下就知道效果了~~
如果你是用的正交摄像机的话;
就调整Size的值,也是一样的~

void Update()
{

    float delX = Input.mousePosition.x - transform.position.x;    float delY = Input.mousePosition.y - transform.position.y;    float scaleX = delX / GetComponent<RectTransform>().rect.width / transform.localScale.x;    float scaleY = delY / GetComponent<RectTransform>().rect.height / transform.localScale.y;    if (Input.GetAxis("Mouse ScrollWheel") > 0)    {        transform.localScale += Vector3.one * 0.1f;    }    else if (Input.GetAxis("Mouse ScrollWheel") < 0)    {        transform.localScale += Vector3.one * -0.1f;    }    GetComponent<RectTransform>().pivot += new Vector2(scaleX, scaleY);    transform.position += new Vector3(delX, delY, 0);}
回复 收起回复
2021-2-23 10:28:27   回复
 赞 赞 0

使用道具 登录

3#
元素果然有不少大神,谢谢分享知识
回复 收起回复
2021-8-28 07:46:35   回复
 赞 赞 2

使用道具 登录

4#
请用鼠标中间的滚轮
回复 收起回复
2021-8-28 13:04:57   回复
 赞 赞 1

使用道具 登录

5#
元素是个好家园,加油啊
回复 收起回复
2022-11-3 17:59:45   回复
 赞 赞 1

使用道具 登录

CG 游戏行业专业问题

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表