wont convert from int to string

Hey there, the following piece of JavaScript code requires a string for the GameObject.Find(“a string”) and I have tried to convert an integer variable to a string so it can be used, but I still get the error message saying:

Assets/Main_02.js(28,44): BCE0017: The best overload for the method ‘UnityEngine.GameObject.Find(String)’ is not compatible with the argument list ‘(int)’.

meaning its still putting in an integer, int.

Could someone please look at my code bellow and tell me whats wrong with it, its probably something realy stupid but i’d be realy grateful, Thank You.


var Y = new Array();

var i:int = 1;

var x:int;


x = i;


var other = GameObject.Find(x);


i+= 1;



variables can’t change the type on the fly unless they are dynamic variables which should be avoided since they are slow. ToString is a function that converts the variable into a string and returns that string. The variable will still be an int. You have to use it like this:

var other = GameObject.Find(x.ToString());

x.ToString() doesn’t change x it just returns the string so you want to do:

   var other = GameObject.Find(x.ToString());