小地图的制作以及摄像机跟随玩家

小地图的制作,创建一个副摄像机,将它的位置移到玩家的上方,选中摄像机,在上方编辑器中选择gameobject,选中图片中选中的选项

 选中副摄像机,找到组件中的图片选项

 就可以开始调整它的视角大小,就做出来了

 摄像机跟随玩家

private Vector3 pos;//摄像机位置
    private Transform player;//玩家位置
    public float up = 3f, away = 4f;//变量
    private float smooth = 4f;//速度
    private Vector3 cameraRotation;//摄像机位置
    private float speed = 3f;//速度
    void Start()
    {
        player = GameObject.FindWithTag("Player").transform;//拿到玩家位置

    }

    // Update is called once per frame
    void Update()
    {
        pos = player.position + Vector3.up * up - Vector3.forward * away;//计算出摄像机的位置
        transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * smooth);//摄像机的位移
        transform.LookAt(player.position);//看向玩家
        CameraChange();
    }
    void CameraChange()
    {
        float x = Input.GetAxis("Mouse X");
        float y = Input.GetAxis("Mouse Y");
        float z = Input.GetAxis("Mouse ScrollWheel");
        if (z<0)
        {
            if (Camera.main.fieldOfView<90)根据鼠标滚轮,将视角放大放小
            {
                Camera.main.fieldOfView += 2;
            }
        }
        if (z > 0)
        {
            if (Camera.main.fieldOfView >30)
            {
                Camera.main.fieldOfView -= 2;
            }
        }
        cameraRotation.x -= y * speed;
        cameraRotation.y += x * speed;
        cameraRotation.x = Mathf.Clamp(transform.position.x, -30, 30);//限定x的范围
        transform.rotation = Quaternion.Euler(cameraRotation.x, cameraRotation.y, 0);//摄像机视角跟随鼠标移动
        player.rotation = Quaternion.Euler(0, cameraRotation.y, 0);//玩家跟随视角一起旋转
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值