学习笔记:
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));
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了