Microsoft PowerPoint - Unity3d_Input

Similar documents
Microsoft PowerPoint - Test.ppt

Microsoft PowerPoint 龍華科技大學遊戲系-Unity teaching

1.ai

建 立 一 面 牆 以 下 說 明 將 會 講 解 比 較 利 用 預 設 物 件 (using a Prefab) 和 從 編 碼 來 創 立 物 件 (creating objects from code) 兩 者 間 的 優 點 首 先, 我 們 用 編 碼 來 建 立 一 面 牆 : fun

Microsoft Word - template.doc

2D Asset Demo Rain Snow SteamSpray VolumeSteam Waterfall Demo Unity Asset store 7.3 2D example\practice\ch07 Unity ch07 MissileExplosion Wall 7-8

崑山科技大學

入 指 令 如 : 鍵 盤 鼠 標 多 點 觸 控 重 力 感 應 陀 螺 儀 等 4. 圖 形 用 戶 接 口 掌 握 引 擎 API 中 GUI 與 GUILayout 類 中 方 法 和 變 量 的 使 用, 能 夠 通 過 GUI Skin 為 應 用 的 界 面 定 制 不 同 風 格 主

void Start () Fire = 0; Fire -= 1 * Time.deltaTime; Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); // 宣告射線 RaycastHit hit; // 射線撞擊 if (

PowerPoint Presentation

Project 1.Demo public Renderer trackl; public Renderer trackr; public float trackspeed = 0.02f; 6-29

p.2 1 <HTML> 2 3 <HEAD> 4 <TITLE> </TITLE> 5 </HEAD> 6 7 <BODY> 8 <H3><B> </B></H3> 9 <H4><I> </I></H4> 10 </BODY> </HTML> 1. HTML 1. 2.

<4D F736F F D C4EAC0EDB9A4C0E04142BCB6D4C4B6C1C5D0B6CFC0FDCCE2BEABD1A15F325F2E646F63>

Chapter 9: Objects and Classes

mvc

Windows XP

HC50246_2009

HC20131_2010

CANVIO_AEROCAST_CS_EN.indd

入學考試網上報名指南

财务制度

Step03 首先先將基礎場景必需物建置完成 新增一個基礎方塊,GameObject > Create Other > Cube: Step04 設置位置至 (0, 0, 0), 並調整大小為 (50, 1, 50): 2

ARM JTAG实时仿真器安装使用指南

2/14 Buffer I12, /* x=2, buffer = I 1 2 */ Buffer I243, /* x=34, buffer = I 2 43 */ x=56, buffer = I243 Buffer I243I265 code_int(int x, char *buffer)

4 Ziggi-HD Plus Ziggi-HD Ziggi-HD Plus 8-9 IPEVO Presenter IPEVO Presenter (AE-Lock)

epub83-1

摘 要 本 校 多 媒 體 設 計 系 與 上 海 戲 劇 學 院 創 意 學 院 在 多 次 聯 繫 交 流 之 下, 已 簽 署 合 作 備 忘 錄, 積 極 尋 求 兩 校 合 作 教 學 與 共 同 創 作 之 機 會 藉 由 本 系 學 生 作 品 腦 殘 公 寓 入 圍 第 五 屆 中

2 黑 色 皇 后 兵 向 前 移 動 兩 格 3 白 色 主 教 兵 4 黑 色 皇 后 對 角 移 動 到 對 吃 掉 白 色 國 王 的 位 置 在 這 個 章 節 中 你 會 學 到 1 打 開 設 定 關 鍵 (Set Key) 模 式 2 使 用 在 檢 視 軌 跡 中 的 可 設 定

DR2010.doc

Microsoft Word - 3D手册2.doc

Move Component Object selection Component selection UV Maya Hotkeys editor Maya USING MAYA POLYGONAL MODELING 55

Ác Åé å Serial ATA ( Sil3132) S A T A (1) SATA (2) BIOS SATA (3)* RAID BIOS RAID (4) SATA (5) SATA (a) S A T A ( S A T A R A I D ) (b) (c) Windows XP

RUN_PC連載_12_.doc

蔡 氏 族 譜 序 2

区 域 活 动 进 入 中 班 我 们 区 域 的 设 置 和 活 动 材 料 都 有 所 变 化, 同 时 也 吸 引 孩 子 们 积 极 的 参 与 学 习 操 作 区 的 新 材 料 他 们 最 喜 欢, 孩 子 们 用 立 方 块 进 行 推 理 操 作 用 扑 克 牌 进 行 接 龙 游

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

软件测试(TA07)第一学期考试

TPM BIOS Infineon TPM Smart TPM Infineon TPM Smart TPM TPM Smart TPM TPM Advanced Mode...8

Microsoft PowerPoint - Lecture7II.ppt

WinMDI 28

MANUAL CHARLS SMS INTERVIEWER MODE

Adobe® Flash® 的 Adobe® ActionScript® 3.0 程式設計

Logitech Wireless Combo MK45 English

Microsoft Word - 01.DOC

<4D F736F F D20C4A3B0E632A3A8D3EFD1D4CEC4D7D6BCECB2E9B8C4A3A92E646F63>

05 01 X Window X Window Linux Linux X Window X Window Webmin Web Linux Linux X Window X Window Notebook PC X Window X Window module Linux Linux kernel

csg(1_29)cs.p65

BlackBerry Classic Smartphone-用户指南

KDC-U5049 KDC-U4049 Made for ipod, and Made for iphone mean that an electronic accessory has been designed to connect specifically to ipod, or iphone,

藍牙網路在資訊家電的應用

Bus Hound 5

Some experiences in working with Madagascar: installa7on & development Tengfei Wang, Peng Zou Tongji university

INTRODUCTION TO COM.DOC

AL-M200 Series

Text 文字输入功能 , 使用者可自行定义文字 高度, 旋转角度 , 行距 , 字间距离 和 倾斜角度。

關於本書 l 3 PhoneGap Appcelerator Titanium Sencha Touch (wrapper framework) Native App PhoneGap Build Native App Hybrid App Java Objective-C Android SDK

投影片 1

Front 2 Polar F11 ( ) : Polar F11 Polar F11 Polar F11 Polar (Keeps U Fit - Own Workout Program) Polar Polar F11 Polar F11 Polar F11 Polar (

untitled


Guide to Install SATA Hard Disks

coverage2.ppt

( )

基于UML建模的管理管理信息系统项目案例导航——VB篇

CC213

XHTML width/height bdo a code href object charset codebase hreflang archive lang type alt dir name name xml:lang rel/rev align shape/coords hspace/vsp

Serial ATA ( Nvidia nforce430)...2 (1) SATA... 2 (2) B I O S S A T A... 3 (3) RAID BIOS RAID... 6 (4) S A T A... 9 (5) S A T A (6) Microsoft Win

TX-NR3030_BAS_Cs_ indd

Gerotor Motors Series Dimensions A,B C T L L G1/2 M G1/ A 4 C H4 E

自动化接口

K7VT2_QIG_v3

untitled

三維空間之機械手臂虛擬實境模擬

幻灯片 1

K301Q-D VRT中英文说明书141009

影視後製全攻略 Premiere Pro After Effects Encore 自序 Adobe Premiere Pro After Effects Encore 2008 Adobe CS Adobe CS5 Adobe CS4 Premiere Pro After Effect

概述

VB程序设计教程

CAUTION RISK OF ELECTRIC SHOCK DO NOT OPEN 2

ebook140-9

Epson

T2 Internal Engineer Prober basic Training Manual T2 Internal Engineer Prober basic training manual - 1 -

CLP-585/575/545/535/565GP

epub 94-3

RUN_PC連載_10_.doc

在挑选合适的 SDK 的时候需要注意, 标准 windows 平台应用选择 FBX SDK VS2015,windows 应用商店和全平台通用的不用考虑 windows 全平台通用的应用是 windows10 新推出的功能, 可以打通 windows phone windows s

软件概述

Microsoft Word - 小心翼翼的二十一點N.doc

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

Transcription:

Unity3d 輸入設備相關指令 ( 滑鼠 鍵盤 搖桿 ) 龍華科技大學多媒體與遊戲發展科學系林志勇編輯請勿外流轉載, 上傳網路 2013/12/28

Mouse( 滑鼠 )

OnMouse(Down, Drag, Enter, Exit, Over, Up) 跟遊戲物件 (GameObject) 有關

OnMouseDown // Loads the level named "SomeLevel" as a response // to the user clicking on the object function OnMouseDown () { } Application.LoadLevel ("SomeLevel");

OnMouseDrag // Darken the material color while user holds down the mouse. function OnMouseDrag () { } renderer.material.color -= Color.white * Time.deltaTime;

OnMouseEnter // Attach this script to a mesh to make // it red when the mouse is over the mesh function OnMouseEnter () { renderer.material.color = Color.red; }

OnMouseExit // Assigns a white color to the material // attached to this mesh. function OnMouseExit () { renderer.material.color = Color.white; }

OnMouseOver // Fades the red component of the material to zero // while the mouse is over the mesh function OnMouseOver () { } renderer.material.color -= Color(0.1, 0, 0) * Time.deltaTime;

OnMouseUp // Register when mouse dragging has ended. OnMouseUp is called // when the mouse button is released. See Also: OnMouseDown, OnMouseDrag. function OnMouseUp () { } Debug.Log("Drag ended!");

Hierarchy Create Sphere 林志勇

OnMouse(Enter, Over, Exit, Down) 透過滑鼠不同動作 改變球的顏色 // Attach this script to a mesh to make // it red when the mouse is over the mesh function OnMouseEnter () { renderer.material.color = Color.red; } function OnMouseOver () { renderer.material.color -= Color(0.1, 0, 0) * Time.deltaTime; } function OnMouseExit () { renderer.material.color = Color.white; } function OnMouseDown () { renderer.material.color = Color.green; } 林志勇

Sphere OnMouse

OnMouseDrag.js var speed = 100; function OnMouseDrag () { transform.position += Vector3.right * Time.deltaTime*Input.GetAxis ("Mouse X") * speed; transform.position += Vector3.forward * Time.deltaTime*Input.GetAxis ("Mouse Y")* speed; } 林志勇

Cube OnMouseDrag 林志勇

JavaScript 與 VC# JavaScript VC#

Input

Input.GetMouse

Input.GetMouse(Button, ButtonDown, ButtonUp) 偵測滑鼠按鈕狀態 ( 跟遊戲物件無關 ) 林志勇

Input.GetMouseButton // Detects clicks from the mouse and prints a message // depending on the click detected. function Update() { if(input.getmousebutton(0)) Debug.Log("Pressed left click."); if(input.getmousebutton(1)) Debug.Log("Pressed right click."); if(input.getmousebutton(2)) Debug.Log("Pressed middle click."); } 林志勇

Input.GetMouseButtonDown // Detects clicks from the mouse and prints a message // depending on the click detected. function Update() { if(input.getmousebuttondown(0)) Debug.Log("Pressed left click."); if(input.getmousebuttondown(1)) Debug.Log("Pressed right click."); if(input.getmousebuttondown(2)) Debug.Log("Pressed middle click."); } 林志勇

Input.GetMouseButtonUp // Detects clicks from the mouse and prints a message // depending on the click detected. function Update() { if(input.getmousebuttonup(0)) Debug.Log("Pressed left click."); if(input.getmousebuttonup(1)) Debug.Log("Pressed right click."); if(input.getmousebuttonup(2)) Debug.Log("Pressed middle click."); } 林志勇

Hierarchy Create GUI Text 林志勇

GetMouse.js function Update() { } if(input.getmousebutton(0)){ guitext.text="pressed left click."; } if(input.getmousebutton(1)){ guitext.text="pressed right click."; } if(input.getmousebutton(2)){ guitext.text="pressed middle click."; } 林志勇

GUI Text GetMouse

MousePosition( 滑鼠位置 ) & RayCast

OnMouse.js Input.mousePosition var particle : GameObject; function Update () { if (Input.GetButtonDown ("Fire1")) { // Construct a ray from the current mouse coordinates var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; if (Physics.Raycast (ray,hit,100)) { // Create a particle if hit Instantiate (particle, hit.point, transform.rotation); } } } 林志勇

Main Camera OnMouse Particle Flame

MouseSensor.js var target1: Transform; var target2: Transform; function Update () { if (Input.GetMouseButton(0)) { var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit: RaycastHit; if (Physics.Raycast(ray, hit)) { if (hit.transform == target1) { print("hit target 1"); } else if (hit.transform == target2) { print("hit target 2"); } } else { print("hit nothing"); } } } Lcy

Main Camera MouseSensor Target1 Cube Target2 Sphere

MouseScrollWheel.js Input.GetAxis("Mouse ScrollWheel") var teststring : String = ""; function OnGUI () { var wheelvalue = Input.GetAxis("Mouse ScrollWheel"); if (wheelvalue!= 0){ teststring = teststring + " " + wheelvalue; GUI.Label(Rect(0,0,320,480),testString); } transform.translate(0, wheelvalue*10,0); } 林志勇

Sphere MouseScrollWheel

Main Camerea MouseXY Lcy

MouseXY.js var mouse : Texture2D; var mouseps = Vector2.zero; function Update () { mouseps = Input.mousePosition; } function OnGUI () { Screen.showCursor = false; GUI.DrawTexture(Rect(mousePs.x,Screen.height-mousePs.y,25,25),mouse); gameobject.find("guitexth").guitext.text ="Screen.height:" +Screen.height.ToString(); gameobject.find("guitexty").guitext.text ="mouseps.y:" +mouseps.y.tostring(); var diffh; diffh=screen.height-mouseps.y; gameobject.find("guitexthy").guitext.text =diffh.tostring(); GUI.DrawTexture(Rect(0,100,25,25),mouse); } Lcy

MouseBMP Lcy

Input.GetButton, GetButtonUp, GetButtonDown

Input.GetButton, GetButtonUp, GetButtonDown

GameObject Create Empty Lcy 37

GameObject Lcy 38

Javascript Lcy 39

InputPress.js function Update () { if(input.getbuttonup("jump")){ Debug.Log("We Have Hit the Space Bar!"); } } Lcy 40

GameObject InputPress Lcy 41

Edit ProjectSettings Input Lcy 42

Name Jump Positive Button space Lcy 43

Input.anyKey, anykeydown 林志勇

Input.anyKey, anykeydown

Input.anyKey // 檢測是否有任何按鍵被按到 function Update() { } if(input.anykey) Debug.Log("A key or mouse click has been detected"); 林志勇

Input.anyKeyDown // 檢測是否有任何按鍵被按到 ( 按下一瞬間 ) function Update() { } if(input.anykeydown) Debug.Log("A key or mouse click has been detected"); 林志勇

inputstring 林志勇

inputstring // Shows how to read typing input from the keyboard // (eg. the user entering his name). // You need to attach this script to a GUIText object. function Update () { for (var c : char in Input.inputString) { // Backspace - Remove the last character if (c == "\b"[0]) { if (guitext.text.length!= 0) guitext.text = guitext.text.substring(0, guitext.text.length - 1); }else if (c == "\n"[0] c == "\r"[0]) { // End of entry // "\n" for Mac, "\r" for windows. print ("User entered his name: " + guitext.text); }else { // Normal text input - just append to the end guitext.text += c; } } } 林志勇

Input.GetKey(Down, Up)

Input.GetKey

Input.GetKey

Input 林志勇

Input 林志勇

Horizontal 林志勇

Vertical 林志勇

Fire1 林志勇

Jump 林志勇

Mouse X 林志勇

Mouse ScrollWheel 林志勇

Window Shake X 林志勇

Horizontal 林志勇

Fire1 林志勇

Jump 林志勇

Input.GetAxis, GetAxisRaw

Input.GetAxis

Input.GetAxis // A very simplistic car driving on the x-z plane. var speed : float = 10.0; var rotationspeed : float = 100.0; function Update () { // Get the horizontal and vertical axis. // By default they are mapped to the arrow keys. // The value is in the range -1 to 1 var translation : float = Input.GetAxis ("Vertical") * speed; var rotation : float = Input.GetAxis ("Horizontal") * rotationspeed; // Make it move 10 meters per second instead of 10 meters per frame... translation *= Time.deltaTime; rotation *= Time.deltaTime; // Move translation along the object's z-axis transform.translate (0, 0, translation); // Rotate around our y-axis transform.rotate (0, rotation, 0); } 林志勇

Input.GetAxis

Input.GetAxis // Performs a mouse look. var horizontalspeed : float = 2.0; var verticalspeed : float = 2.0; function Update () { // Get the mouse delta. This is not in the range -1...1 var h : float = horizontalspeed * Input.GetAxis ("Mouse X"); var v : float = verticalspeed * Input.GetAxis ("Mouse Y"); transform.rotate (v, h, 0); }

Input.GetAxisRaw function Update () { } var speed : float = Input.GetAxisRaw("Horizontal") * Time.deltaTime; transform.rotate (0, speed, 0); 林志勇

Input Size 18 25 林志勇

Input Rename 林志勇

Input 林志勇

Input.GetJoystickNames // Prints a joystick name if movement is detected. function Update () { } // requires you to set up axes "Joy0X" - "Joy3X" and "Joy0Y" - "Joy3Y" in the Input Manger for (var i : int = 0; i < 4; i++) { } if (Mathf.Abs(Input.GetAxis("Joy"+i+"X")) > 0.2 Mathf.Abs(Input.GetAxis("Joy"+i+"Y")) > 0.2) Debug.Log (Input.GetJoystickNames()[i]+" is moved"); 林志勇

搖桿 (JoyStick)

讀取搖桿狀態函數 Input.GetAxis("X axis") Input.GetAxisRaw("X axis") Input.GetButton("joystick button 0") 無法區分不同搖桿按鈕 Input.GetKey(KeyCode.Joystick1Button0) 可區分不同搖桿按鈕

搖桿按鈕替代鍵碼 KeyCode.JoystickButton0

讀取搖桿旋轉軸數值 Input.GetAxis

Input.GetAxis ( Vertical ) ( 垂直軸 ) Input.GetAxis ( Horizontal )( 水平軸 ) // A very simplistic car driving on the x-z plane. var speed : float = 10.0; var rotationspeed : float = 100.0; function Update () { // Get the horizontal and vertical axis. // By default they are mapped to the arrow keys. // The value is in the range -1 to 1 var translation : float = Input.GetAxis ("Vertical") * speed; var rotation : float = Input.GetAxis ("Horizontal") * rotationspeed; // Make it move 10 meters per second instead of 10 meters per frame... translation *= Time.deltaTime; rotation *= Time.deltaTime; // Move translation along the object's z-axis transform.translate (0, 0, translation); // Rotate around our y-axis transform.rotate (0, rotation, 0); }

讀取搖桿旋轉軸值及按鈕值

讀取搖桿旋轉軸值及按鈕值 var speed : float = 10.0; var rotationspeed : float = 10.0; function Update () { if(input.getkey(keycode.joystickbutton0)) { transform.rotate(5, 0, 0); print("up arrow key is held down"); } if(input.getkey("joystick button 1")) { transform.rotate(0, 5, 0); print("up arrow key is held down"); } if(input.getkey("joystick button 2")) { transform.rotate(0, 0, 5); print("up arrow key is held down"); } var translation : float = Input.GetAxis ("Vertical") * speed; var rotation : float = Input.GetAxis ("Horizontal") * rotationspeed; // Make it move 10 meters per second instead of 10 meters per frame... translation *= 0.1; rotation *= 0.01; // Move translation along the object's z-axis transform.translate (0, 0, translation); // Rotate around our y-axis transform.translate (rotation, 0, 0); }

範例程式 http://wiki.etc.cmu.edu/unity3d/index.php/joystick/controller

Arcade Stick for Sony Playstation 3

Microsoft Xbox 360 Controller

搖桿示意圖

測試程式介面

搖桿輸入裝置設定 Edit Project Settings Input

增加 Size 數量, 設定新增搖桿轉軸

測試程式

讀取搖桿按鈕值 Input.GetKey(KeyCode.Joystick4Button0)

讀取搖桿轉軸數值 Input.GetAxisRaw("J2-3")

無線搖桿控制台 裝置管理員 人性介面裝置

羅技搖桿測試程式搖桿 1,2,4 對應 Unity3d Joystick1,2,4( 無 Joystick 3)

Mode 亮 x, y Axis 5th, 6thAxis

Mode 不亮 5th, 6thAxis x, y Axis

Input.GetButton(Down, Up)

Input.GetButton

Unity3d IPhone

Android 手機 Bundle Identifier 設定

Bundle Identifier Bundle Identifier: Bundle Identifier 就是 package name Package Name 可自訂任何名字, 但業界有通用格式, 例如 : com.mycompanyname.mygame net.yourcompanyname.yourgame Bundle Identifier(Package Name) 在上架 Android Market 時, 很重要 因為同一個 PackageName 只能存在一個 Bundle Identifier(PackageName) 取 com.mywebsite.mygame, 但是已經有人取這個名字並已上架了,Android Market 就不會讓你用同樣的名字 簡單來說, 就是作為獨一的識別名字 Bundle Version: 備註程式第幾版本 Bundle Code: 備註程式是哪一個小版號

iphoneutils.vibrate(); 手機震動 // Press button to vibrate function OnGUI() { } if (GUI.Button(Rect(0, 10, 100, 32), "Vibrate!")) iphoneutils.vibrate();

Input.GetTouch Input.touchCount TouchPhase.Moved TouchPhase.Began

Touch

TouchPhase

Input.touchCount

Input.GetTouch

Input.acceleration

Screen.orientation

Input.deviceOrientation

Input.gyro

省電 // Disable screen dimming Screen.sleepTimeout = 0.0f;

http://unity3d.com/support/documentation/script Reference/Screen.html

// Start in landscape mode function Start () { Screen.orientation = ScreenOrientation.LandscapeLeft; }