• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
学习笔记
Misaka的学习笔记
博客园    首页    新随笔    联系   管理    订阅  订阅
unity中Input.GetAxis()用法
 

学习笔记:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TransformPointTest : MonoBehaviour {

    public Transform Cube;

    void FixedUpdate ()
    {
       // vector3.clampMagnitude(vector,maxlength)
       //返回原向量vector的拷贝,并且它的模长最大不超过maxlength的长度
       Cube.position =  Vector3.ClampMagnitude(Cube.position, 5);

       float x= Input.GetAxis("Horizontal");//对应键盘上的A键和D键 或←键和→键
       float z = Input.GetAxis("Vertical"); //对应键盘上的W键和S键 或↑键和↓键
       float h = Input.GetAxis("Mouse X"); //对应X方向上鼠标的移动,在移动设备上也可以这样
       float v = Input.GetAxis("Mouse Y"); //对应Y方向上鼠标的移动,在移动设备上也可以这样
       float m = Input.GetAxis("Fire1");  //对应鼠标左键或left+Ctrl
       float n = Input.GetAxis("Fire2");  //对应鼠标右键或left+Alt
       float k = Input.GetAxis("Fire3");  //对应鼠标中键或left+shift
        float m1 = Input.GetAxisRaw("Fire1");
        //input.getAxis()和input.getAxisRaw()的区别
        //input.getAxis()的返回值m从0渐变为1或者-1
        //input.getAxisRaw()的返回值从0变成1或者-1,没有渐变
        // transform.Translate(x,0,z);
        // transform.Translate(h,0,v);
         transform.Translate(0,0,m1);

playerrb.AddForce(new Vector3(x,0,z));


    }

}

 

 
posted on 2023-08-14 20:48  我们打工人  阅读(203)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3