- Home /
Question by
soeiromass · Nov 21, 2016 at 10:10 PM ·
c#androidkeyboard
Drag GameObject with a Key
I'm used to use a mouse drag, code:
// Use this for initialization
void Start ()
{
path = Application.loadedLevelName + ".xls";
}
// Update is called once per frame
void Update () {
Screen.lockCursor = false;
Cursor.visible = true;
if (Input.GetKeyDown (KeyCode.R))
{
Application.LoadLevel("cozinha");
}
}
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
StreamWriter sw = new StreamWriter (path, true);
sw.WriteLine (this.name + "\t" + Mathf.Round(Time.timeSinceLevelLoad));
sw.Close ();
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint);
transform.position = curPosition;
}
But this only work when I press fire1 of mouse.
My question is: how can I do the same movement but this time using a keyboard key ?
This code works perfectly, but when I use cardBoard I don't have a mouse with me, I only have a Gamepand where gives me a 'K' of keyboard.
Thank you all.
Comment
Your answer
