Skip to main content

After editing a Textfield, how to trigger an event using Return/Enter key in Unity

function OnGUI()
chatInput = GUILayout.TextField(chatInput);

if (GUI.changed)
            Debug.Log("Text field has changed.");
            activeReturnKey = true;
            if(Event.current.isKey && Event.current.keyCode ==           KeyCode.Return) //Input.GetKeyDown(KeyCode.Return))
                                  print ("ReturnPressed");
                                  activeReturnKey = false;


function SendChat( info : String)


Popular posts from this blog

How to write data to CSV file in UNITY

Hi Guys, if any one is facing problem to save data in csv file can use this solution. If you have any questions, you can ask me through comments.

Things to remember :
Never ever add any commas to your data otherwise, cells will get messed up completely. 

Results :

Here is the code


publicclassCsvReadWrite : MonoBehaviour {

privateList<string[]> rowData = newList<string[]>();

voidStart () {


string[] rowDataTemp = newstring[3];
rowDataTemp[0] = "Name";
rowDataTemp[1] = "ID";
rowDataTemp[2] = "Income";


Simple Up, Down, Left, Right Swipe controls for touch devices( Iphone and Android) in unity

Note: There are more than 50 comments in this post, So, if your comment is not appearing on the first page than' 'don't get panic', there is aLoad Morebutton at the bottom of the page.

Here is a UnityScript (javascript version)

#pragma strict
var player : Transform;  // Drag your player here
privatevar fp : Vector2;  // first finger position
privatevar lp : Vector2;  // last finger position

function Update()
for (var touch : Touchin Input.touches)
if (touch.phase == TouchPhase.Began)
fp = touch.position;
lp = touch.position;
if (touch.phase == TouchPhase.Moved )
lp = touch.position;
if(touch.phase == TouchPhase.Ended)

if((fp.x - lp.x) > 80) // left swipe


else if((fp.x - lp.x) < -80) // right swipe
else if((fp.y - lp.y) < -80 ) // up swipe
// add your jumping code here


add this script to any empty gameObject or your player than drag your player to player variable in editor now build a .apk or .ipa and check the re…

How to create line graph in unity

Hi guys, previously i have shown how you can create Bar_Graph in unity, after successfully showing bar graph in unity i fell in love with graphs, so when i was asked to show data on a line graph, i got excited and came up with this solution, its almost similar to the bar graph, but this time i have made it more reliable and dynamic.

this is how my setup looks like :

I have an orthographic camera in my scene, which only renders a layer i namded "GUI". and every gameobject in the graph are in "GUI" layer.

why orthographic camera ? its because they easily adjust according to different screen resolutions, i have also used textMesh to show the numbers in graph, which again is the best option if you want to show text in 3d space.

here is a view, how the final graph looks like with data :

in the above image you can see that i am showing data for 99 turns,  but in this small space i cant show data for all the 99 turns, so what i did is i made a dynamic function which give…