您当前的位置: 首页 >  unity

苍狼王unity学院

暂无认证

  • 0浏览

    0关注

    305博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity 制作第一人称角色控制器、移动和视角控制

苍狼王unity学院 发布时间:2019-08-14 16:23:44 ,浏览量:0

1、player1面板 在这里插入图片描述 2、player下加上一个摄像机。 3、脚本如下:

public class player : MonoBehaviour
{
    private float moveSpeed;//摄像机的移动速度
    public GameObject Eye;
    void Start()
    {
        moveSpeed = -8;
    }
    Vector3 rot = new Vector3(0, 0, 0);
    void Update()
    {
        //鼠键控制移动
        WASD();
        if (Input.anyKey)
        {
            this.GetComponent().constraints = RigidbodyConstraints.FreezeRotation;
        }
        else
        {
            this.GetComponent().constraints = RigidbodyConstraints.FreezeAll;
        }
    }
    /// 
    /// 鼠键控制player移动
    /// 
    void WASD()
    {
        if (Input.GetMouseButton(1))
        {
            if (Input.GetAxis("Mouse X") != 0)
            {
                //Debug.Log(Input.GetAxis("Mouse X"));
             
关注
打赏
1665389160
查看更多评论
立即登录/注册

微信扫码登录

0.1448s