用户输入- Unity3D游戏开发培训
2018-02-12 00:56
204 查看
用户输入-Unity3D游戏开发培训
作者:邓家海
时间:2018-02-1214:28:45
-方法:GetMouseButton();
-方法:GetMouseButtonDown()
-方法:GetMouseButtonUp()
-参数为int,0表示左键,1表示右键,2表示滚轮
键盘输入
-方法:GetKey()
-方法:GetKeyDown()
-方法:GetKeyUp()
-参数为KeyCode枚举,表示按的某个键
位置:属性position,方法Translate()
旋转:方法Rotate(),方法RotateAround()
缩放:属性localScale
类Vector3:表示三维向量,可以理解为三维空间中的点
-成员up、down、left、fight、forward、back、zero、one
图3-1
会在浏览器打开API文档.
图3-2
图3-3
新建两个场景.File->newSence
图3-4
新建一个空对象create->createEmpty,命名script,reset一下Tranform
新建一个C#脚本,双击打开脚本
图3-5
脚本原始的样子是这样的,什么也没有,只有两个方法:
选中新建的script场景,然后Edit->ProjectSettings->input,然后设置input的属性。
图3-6
图3-7
Window->Console打开控制台,控制台一般用于打印错误消息或者调试。
调试一下
图3-8
vector3
图3-9
图3-10
图3-11
图3-12
作者:邓家海
时间:2018-02-1214:28:45
用户输入Input
鼠标按键:-方法:GetMouseButton();
-方法:GetMouseButtonDown()
-方法:GetMouseButtonUp()
-参数为int,0表示左键,1表示右键,2表示滚轮
键盘输入
-方法:GetKey()
-方法:GetKeyDown()
-方法:GetKeyUp()
-参数为KeyCode枚举,表示按的某个键
控制对象
控制对象的位置、旋转、缩放位置:属性position,方法Translate()
旋转:方法Rotate(),方法RotateAround()
缩放:属性localScale
类Vector3:表示三维向量,可以理解为三维空间中的点
-成员up、down、left、fight、forward、back、zero、one
Entity3DAPI
点击Help->UnityManual图3-1
会在浏览器打开API文档.
图3-2
图3-3
新建两个场景.File->newSence
图3-4
新建一个空对象create->createEmpty,命名script,reset一下Tranform
新建一个C#脚本,双击打开脚本
图3-5
脚本原始的样子是这样的,什么也没有,只有两个方法:
usingUnityEngine; usingSystem.Collections; ///作者:邓家海 ///用户:DengJiaHai ///创建日期:2017-01-1022:50:52 ///修改: ///版本:V1.0.0.0 //添加菜单名字 [AddComponentMenu("Demo2/InputTest1")] publicclassInputTest:MonoBehaviour{ //Usethisforinitialization voidStart(){ } //Updateiscalledonceperframe voidUpdate(){ if(Input.GetButton("Fire1")) { print("button"); } if(Input.GetButtonDown("Fire1")) { print("down"); } if(Input.GetButtonUp("Fire1")) { print("up"); } } }
选中新建的script场景,然后Edit->ProjectSettings->input,然后设置input的属性。
图3-6
图3-7
Window->Console打开控制台,控制台一般用于打印错误消息或者调试。
调试一下
图3-8
vector3
图3-9
图3-10
图3-11
usingUnityEngine; usingSystem.Collections; publicclassExampleClass:MonoBehaviour{ voidSlide(Transformtarget,Vector3railDirection){ Vector3heading=target.position-transform.position; Vector3force=Vector3.Project(heading,railDirection); GetComponent<Rigidbody>().AddForce(force); } }
图3-12
usingUnityEngine; usingSystem.Collections; publicclassExampleClass:MonoBehaviour{ publicTransformstartMarker; publicTransformendMarker; publicfloatspeed=1.0F; privatefloatstartTime; privatefloatjourneyLength; voidStart(){ startTime=Time.time; journeyLength=Vector3.Distance(startMarker.position,endMarker.position); } voidUpdate(){ floatdistCovered=(Time.time-startTime)*speed; floatfracJourney=distCovered/journeyLength; transform.position=Vector3.Lerp(startMarker.position,endMarker.position,fracJourney); } }
相关文章推荐
- JAVA游戏入门开发DAY 3 接收用户输入
- Unity3D 游戏开发构架篇 ——输入控制
- 内置3D对象-Unity3D游戏开发培训
- 7小时Unity3D游戏开发培训教程
- 投影方式- Unity3D游戏开发培训
- Unity3D 游戏开发构架篇 ——输入控制
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(五)----使用TextField 输入并调整排名
- [Unity3D]手机3D游戏开发:如何实现最高分的存储与显示(七)----使用Game ID避免数据重复输入
- 7小时Unity3D游戏开发培训教程
- 【Unity3D游戏开发学习笔记】(八)Unity观察视角的实现
- Unity3D游戏开发框架-资源管理类ResourceManage
- unity3D游戏开发八之天空盒
- 游戏开发之输入控制类测试代码
- Unity3D游戏引擎实战开发从入门到精通(坦克大战项目实战、NGUI开发、GameObject)
- iOS开发中苹果输入手机号变用户的名字
- Unity3d游戏开发框架-标志量-数学管理类-时间管理-Log日志管理
- U3d学习-使用Unity3D开发2D游戏(上)
- Unity3D 游戏开发day01
- unity3d开发2d游戏中控制摄像机移动以及主角移动
- 游戏开发设计模式之对象池模式(unity3d 示例实现)