- Home /
Question by
ari nur rohman · Mar 11, 2014 at 04:51 AM ·
windows-7getkeyup
Get key up in windows in Android?
using UnityEngine;
public class Player : MonoBehaviour { // The force which is added when the player jumps // This can be changed in the Inspector window public Vector2 jumpForce = new Vector2(0, 300);
// Update is called once per frame
void Update ()
{
// Jump
if (Input.GetKeyUp("space"))
{
rigidbody2D.velocity = Vector2.zero;
rigidbody2D.AddForce(jumpForce);
}
}
}
in Windows if (Input.GetKeyUp("space")) { rigidbody2D.velocity = Vector2.zero; rigidbody2D.AddForce(jumpForce); }
But in Android How c#Scripts touchscreen in android
Please Help mee
Comment
Answer by zharik86 · Mar 11, 2014 at 07:07 AM
For example, in function LateUpdate() to write the following (I write on memory therefore there can be some inaccuracies):
//Touch an event shall be bound to certain coordinates on the screen therefore for an example I took GUITextures.
public GUITexture[] listBtn = null; // our list buttons as GuiTexture
void LateUpdate() {
if(Input.touchCount > 0) {
for (int i = 0; i<Input.touchCount; i++) {
if (Input.getTouch(i).phase == TouchPhase.Ended) { //Ended equal keyUp
float x = Input.getTouch(i).position.x;
float y = Input.getTouch(i).position.y;
for(int j=0; j<listBtn.Length; j++) {
if (listBtn[j].getScreenRect().Contains(Input.getTouch(i)) {
if (j == 0) // some code for button number 0
if (j == 1) // some code for button number 1
}
}
}
}
}
}
We check all event touch for the ended of a contact of the screen. If there are questions that ask. I hope it to you will help.