PowenKo, Unity 3D, Input, Input.GetKeyUp, Input.GetKeyDown

September 6, 2011   ·   0 Comments

using UnityEngine;
using System.Collections;

public class keycodeEventC : MonoBehaviour {

    private  string[] line=new string[5];
	public  GameObject[] thing=new GameObject[5];

	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {

		//http://unity3d.com/support/documentation/ScriptReference/KeyCode.Space.html?from=Input
    	//if (Input.GetKeyDown (KeyCode.Space ))
		if (Input.GetKeyDown(KeyCode.UpArrow)){       Fun_Rotare(0,"UpArrow");
		}else if (Input.GetKeyUp (KeyCode.UpArrow)){  Fun_Rotare(0,"");
		}else if (Input.GetKeyDown(KeyCode.DownArrow)){  Fun_Rotare(1,"DownArrow");
		}else if (Input.GetKeyUp  (KeyCode.DownArrow)){  Fun_Rotare(1,"");
		}else if (Input.GetKeyDown(KeyCode.LeftArrow)){  Fun_Rotare(2,"LeftArrow");
		}else if (Input.GetKeyUp  (KeyCode.LeftArrow)){  Fun_Rotare(2,"");
		}else if (Input.GetKeyDown(KeyCode.RightArrow)){  Fun_Rotare(3,"RightArrow");
		}else if (Input.GetKeyUp  (KeyCode.RightArrow)){  Fun_Rotare(3,"");
		}else if (Input.GetKeyDown("space")){  Fun_Rotare(4,"space");
		}else if (Input.GetKeyUp  ("space")){  Fun_Rotare(4,"");
		}
	}
	void Fun_Rotare(int i_objNo,string i_String){

		line[i_objNo]=i_String;
		if(i_String==""){
			thing[i_objNo].transform.Rotate(0,0,-60); //flip the turtle
		}else{
			thing[i_objNo].transform.Rotate(0,0,60); //flip the turtle
		}

	}

	void OnGUI () {
	GUI.color =new  Color(0,0.9f,0);
	GUI.Label (new Rect (0, 0, 500, 20), "PowenKo.com");
	GUI.Label (new Rect (20, 35, 500, 20), line[0]);
	GUI.Label (new Rect (20, 50, 500, 20), line[1]);
	GUI.Label (new Rect (20, 65, 500, 20), line[2]);
	GUI.Label (new Rect (20, 80, 500, 20), line[3]);
	GUI.Label (new Rect (20, 95, 500, 20), line[4]);
	}
}

sample code:

b38_input_keycode

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon