100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > unity 第三人称射击游戏的摄像机实现

unity 第三人称射击游戏的摄像机实现

时间:2019-09-08 03:25:13

相关推荐

unity 第三人称射击游戏的摄像机实现

把摄像机放在人物GameObject里面,位置设置在一个合适的位置,前后左右移动,就都会带者摄像机移动了在脚本中得到摄像机,并获取鼠标x,y轴的偏移量鼠标x轴的偏移量,直接用来旋转人物的y轴,这样带者摄像机也会旋转鼠标y轴的偏移量,用来让相机绕着人物的x轴旋转

代码实现:

using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class PlayerMove : MonoBehaviour{private Camera mCamera;// Start is called before the first frame updatevoid Start(){mCamera = transform.Find("PlayerCamera").GetComponent<Camera>();}// Update is called once per framevoid Update(){float x = Input.GetAxisRaw("Mouse X");float y = Input.GetAxisRaw("Mouse Y");//鼠标x轴的偏移量,直接用来旋转人物的y轴transform.Rotate(new Vector3(0, x, 0), Space.Self);//鼠标y轴的偏移量,用来让相机绕着人物的x轴旋转 mCamera.transform.RotateAround(transform.position,transform.right,-y);}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。