UNİTY 3D GET BUTTON AND GET KEY
Bu Derste Get Key Get Button Arasındaki Farkları Öğreneceksiniz
KEY INPUT:
C#
using UnityEngine;
using System.Collections;
public class KeyInput : MonoBehaviour
{
public GUITexture graphic;
public Texture2D standard;
public Texture2D downgfx;
public Texture2D upgfx;
public Texture2D heldgfx;
void Start()
{
graphic.texture = standard;
}
void Update ()
{
bool down = Input.GetKeyDown(KeyCode.Space);
bool held = Input.GetKey(KeyCode.Space);
bool up = Input.GetKeyUp(KeyCode.Space);
if(down)
{
graphic.texture = downgfx;
}
else if(held)
{
graphic.texture = heldgfx;
}
else if(up)
{
graphic.texture = upgfx;
}
else
{
graphic.texture = standard;
}
guiText.text = " " + down + "\n " + held + "\n " + up;
}
}
JS
#pragma strict
public var graphic : GUITexture;
public var standard : Texture2D;
public var downgfx : Texture2D;
public var upgfx : Texture2D;
public var heldgfx : Texture2D;
function Start()
{
graphic.texture = standard;
}
function Update ()
{
var down = Input.GetKeyDown(KeyCode.Space);
var held = Input.GetKey(KeyCode.Space);
var up = Input.GetKeyUp(KeyCode.Space);
if(down)
{
graphic.texture = downgfx;
}
else if(held)
{
graphic.texture = heldgfx;
}
else if(up)
{
graphic.texture = upgfx;
}
else
{
graphic.texture = standard;
}
guiText.text = " " + down + "\n " + held + "\n " + up;
}
BUTTON INPUT:
C#
using UnityEngine;
using System.Collections;
public class ButtonInput : MonoBehaviour
{
public GUITexture graphic;
public Texture2D standard;
public Texture2D downgfx;
public Texture2D upgfx;
public Texture2D heldgfx;
void Start()
{
graphic.texture = standard;
}
void Update ()
{
bool down = Input.GetButtonDown("Jump");
bool held = Input.GetButton("Jump");
bool up = Input.GetButtonUp("Jump");
if(down)
{
graphic.texture = downgfx;
}
else if(held)
{
graphic.texture = heldgfx;
}
else if(up)
{
graphic.texture = upgfx;
}
else
{
graphic.texture = standard;
}
guiText.text = " " + down + "\n " + held + "\n " + up;
}
}
JS
#pragma strict
public var graphic : GUITexture;
public var standard : Texture2D;
public var downgfx : Texture2D;
public var upgfx : Texture2D;
public var heldgfx : Texture2D;
function Start()
{
graphic.texture = standard;
}
function Update ()
{
var down = Input.GetButtonDown("Jump");
var held = Input.GetButton("Jump");
var up = Input.GetButtonUp("Jump");
if(down)
{
graphic.texture = downgfx;
}
else if(held)
{
graphic.texture = heldgfx;
}
else if(up)
{
graphic.texture = upgfx;
}
else
{
graphic.texture = standard;
}
guiText.text = " " + down + "\n " + held + "\n " + up;
}