Skip to main content


Showing posts from 2012

Read and Write XML using javascript in unity

Here i am posting a script, which saves data to XML and read that saved data from XML. It also shows read data in a GUI.
I would like to thanks for there Tutorial on Xml, Though those where on C# but i tried to convert them in unity javascript( js )

Before starting, first always prepare a structure for your xml (the way you want to save your data in XML ), than its much easier to create a script which will follow a pattern to save your data and it will follow same pattern to read your data from XML. For the first timer who don't know about xml I would like to recommend this tutorial on xml.
My XML Stock.xml
<Stock> <ABC> <Price>45</Price> <Qnty>54</Qnty> </ABC> <XYZ> <Price>45</Price> <Qnty>3</Qnty> </XYZ> </Stock>

Here is the full script, and you can find the project link below.

#pragma strict import System.Collections.Generic; import S…

Convert String to Float using JavaScript in Unity

#pragma strict
var stringFloatValue : String = "";  // use to store float value inserted by user in TextField

var stringIntValue : String = "";     // use to store int value inserted by user in TextField

var FloatValue : float;
var IntValue : int;

function OnGUI() {


    stringFloatValue = GUI.TextField (Rect (0, 40, 80, 30), stringFloatValue, 25);

    stringIntValue = GUI.TextField (Rect (0, 80, 80, 30), stringIntValue, 25);


GUI.Box(Rect(105,40,80,30), FloatValue.ToString());

GUI.Box(Rect(105,80,80,30), IntValue.ToString());

if(float.TryParse(stringFloatValue,FloatValue))  // checking if user entered a valid string
            FloatValue = float.Parse(stringFloatValue);    // converting string to float
if(System.Int32.TryParse(stringIntValue,IntValue))  // checking i…