Unity3D常用脚本PDF.pdf

上传人:xiang****la438 文档编号:133290366 上传时间:2020-05-26 格式:PDF 页数:16 大小:561.32KB
返回 下载 相关 举报
Unity3D常用脚本PDF.pdf_第1页
第1页 / 共16页
Unity3D常用脚本PDF.pdf_第2页
第2页 / 共16页
Unity3D常用脚本PDF.pdf_第3页
第3页 / 共16页
亲,该文档总共16页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Unity3D常用脚本PDF.pdf》由会员分享,可在线阅读,更多相关《Unity3D常用脚本PDF.pdf(16页珍藏版)》请在金锄头文库上搜索。

1、书 山 有 路 1 场景转换 var screenbutton boolean function Start DontDestroyOnLoad this screenbutton true function Update if Input GetKeyDown KeyCode Escape screenbutton true function OnGUI if screenbutton true if GUI Button Rect Screen width 2 380 Screen height 2 190 60 50 Scene1 print You click Scene1 Appli

2、cation LoadLevel 1 screenbutton false else if GUI Button Rect Screen width 2 380 Screen height 2 130 60 50 Scene2 print You click Scene2 Application LoadLevel 2 screenbutton false else if GUI Button Rect Screen width 2 375 Screen height 2 0 50 50 Quit print You click Quit Application Quit 心得 场景转换时 这

3、个程序贴在按钮界面场景中 在 Build Setting 导出 在 File 下 菜单中加 入所需场景 书 山 有 路 2 0 为按钮界面 可以无限增加场景 else if GUI Button Rect Screen width 2 380 Screen height 2 130 60 50 Scene2 print You click Scene2 Application LoadLevel 2 screenbutton false 复制此段程序并做修改 运动控制键 上下左右 var TankSpeed int 20 function Update if Input GetKey KeyC

4、ode W print go transform Translate Vector3 forward Time deltaTime TankSpeed else if Input GetKey KeyCode S print go back transform Translate Vector3 forward Time deltaTime TankSpeed else if Input GetKey KeyCode A print turn left transform Rotate Vector3 up Time deltaTime TankSpeed else if Input GetK

5、ey KeyCode D print turn right transform Rotate Vector3 up Time deltaTime TankSpeed 书 山 有 路 3 需要放在第一视角的物体或者摄像机上 加天空背景 菜单栏 Component 下的 Rendering 下的 Skybox 将他加在所需场景的摄像机上 选择所需的 天空 运行时自然出现 各种按钮汇总 书 山 有 路 4 鼠标碰触后显示说明文字 function OnGUI GUI Button Rect 0 0 100 20 GUIContent Click me This is the tooltip GUI

6、Label Rect 0 40 100 40 GUI tooltip 多项选择 以上都选择 var allOptions true var extended1 true var extended2 true function OnGUI allOptions GUI Toggle Rect 0 120 150 20 allOptions Edit All Options GUI enabled allOptions extended1 GUI Toggle Rect 20 70 130 20 extended1 Extended Option 1 extended2 GUI Toggle Re

7、ct 20 90 130 20 extended2 Extended Option 2 书 山 有 路 5 GUI enabled true if GUI Button Rect 0 160 150 20 Ok print user clicked ok 鼠标碰触第一个按钮有解释 鼠标碰触第三个对话框有解释 碰第二个没有解释 function OnGUI GUI Box Rect 5 300 110 75 GUIContent Box This box has a tooltip GUI Button Rect 10 230 100 20 No tooltip here GUI Button

8、Rect 10 200 100 20 GUIContent I have a tooltip The button overrides the box GUI Label Rect 10 260 100 40 GUI tooltip 半透明 说明性文字对话框 无选择 function Update 书 山 有 路 6 function OnGUI GUI BeginGroup new Rect Screen width 2 400 Screen height 2 300 800 600 GUI Box new Rect 0 0 800 600 This box is now centered

9、here you would put your main menu GUI EndGroup 滚动条 选择按钮 可以放多个按钮并且节省位置 function Update var scrollPosition Vector2 zero function OnGUI scrollPosition GUI BeginScrollView Rect 10 400 100 100 scrollPosition Rect 0 0 220 200 GUI Button Rect 0 0 100 20 Top left GUI Button Rect 120 0 100 20 Top right GUI B

10、utton Rect 0 180 100 20 Bottom left GUI Button Rect 120 180 100 20 Bottom right GUI EndScrollView 书 山 有 路 7 循环的字幕 var letterPause 0 2 定义每个字出现的时间间隔 var sound AudioClip 打字机的声音 private var word 存储你打字机效果想要输出的字的变量 private var Text String My name is Ray Yang Keep it in your heart 你希望打字机效果输出 的字 function St

11、art word Text 把你输出的字先赋值给 word Text 把你要显示的字先抹除 以便你可以在最初显示的时候显示为空 当然你也可以 加上其他字 让他先显示 打字机效果打的字会显示在这个后面 yield WaitForSeconds 2 TypeText function OnGUI GUI Label Rect 150 15 250 25 Please answer my question who am I GUI Box Rect 150 40 250 25 Text function TypeText for var letter in word ToCharArray 做一个循

12、环 定义一个变量 letter 逐次等于 word 中的 每一个字符 Text letter 把这些字赋值给 Text if sound 控制声音 出现一个字 发一个声音 书 山 有 路 8 audio PlayOneShot sound yield WaitForSeconds letterPause function Update if Text word Text TypeText 有打字声音的字幕循环 var screnbutton boolean var icon Texture var allOptions true var extended1 true var extended2

13、 true var letterPause 0 2 定义每个字出现的时间间隔 var sound AudioClip 打字机的声音 private var word 存储你打字机效果想要输出的字的变量 static var Text String This is zcx first project I can do it var del boolean false var particle GameObject function Start DontDestroyOnLoad this screnbutton true word Text Text yield WaitForSeconds 2

14、 TypeText 书 山 有 路 9 function Update if Input GetKeyDown KeyCode Escape screnbutton true if Text This is zcx first project I can do it Text TypeText if Input GetMouseButtonDown 0 Text for var c char in Input inputString Backspace Remove the last character if c b if guiText text Length 0 guiText text

15、guiText text Substring 0 guiText text Length 1 End of entry else if c n print User entered his name guiText text Normal text input just append to the end else guiText text c function OnGUI if screnbutton true if GUI Button Rect Screen width 2 30 Screen height 2 30 60 50 scene1 print you click Scene

16、1 Application LoadLevel 1 screnbutton false else if GUI Button Rect Screen width 2 30 Screen height 2 30 60 50 scene2 print you click Scene 2 Application LoadLevel 2 screnbutton false else if GUI Button Rect Screen width 2 30 Screen height 2 90 60 50 scene3 print you click Scene 3 书 山 有 路 10 Application LoadLevel 3 screnbutton false else if GUI Button Rect Screen width 2 30 Screen height 2 150 60 50 Quit print you click Quit Application Quit GUI Button Rect 0 0 100 20 Click Me GUI Button Rect 0

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号