Escolar Documentos
Profissional Documentos
Cultura Documentos
()
2013/12/28
Mouse()
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!");
}
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.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.");
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.";
}
}
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);
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
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
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
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
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 {
// 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 1825
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)()
http://wiki.etc.cmu.edu/unity3d/index.php/Joystick/Controller
EditProject SettingsInput
Size
Input.GetKey(KeyCode.Joystick4Button0)
Input.GetAxisRaw("J2-3")
1,2,4Unity3d 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
Bundle Identifier
Bundle Identifier
Bundle Identifierpackage namePackage 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();
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