- Home /
Question by
Joetjah · Jan 24, 2013 at 08:52 PM ·
javascriptarrayhitindexof
Search a substring in an array of Strings
I'm trying to search a substring in an array of Strings. I'm using the following code:
var obstacles = ["Border", "Boundary", "BoundaryFlame"];
var hitFront: RaycastHit;
if (Physics.Raycast(transform.position, Vector3.forward, hitFront, 1)) {
for (var i = 0; i < obstacles.length; i++)
{
if (obstacles[i].indexOf(hitFront.collider.gameObject.name) > 0)
{
//Do something
}
}
}
I'm getting the following error:
MissingMethodException: Method not found: 'System.String.indexOf'.
What am I doing wrong?
Comment
Remember that "Javascript" in Unity is not really Javascript and doesn't use any Javascript functions. It uses .NET (or technically $$anonymous$$ono), which always uses uppercase for methods.
Best Answer
Answer by Dave-Carlile · Jan 24, 2013 at 08:59 PM
I believe String.IndexOf should have an upper case I.
So...
if (obstacles[i].IndexOf(....