我正在尝试在字符串数组中搜索子字符串。我正在使用以下代码(在 Unity3 中):
var obstacles = ["Border", "Boundary", "BoundaryFlame"];
var frontAvailable = true;
var leftAvailable = true;
var rightAvailable = true;
var hitFront: RaycastHit;
if (Physics.Raycast(transform.position, transform.position + transform.forward, hitFront, 1.5)) {
Debug.Log("I hit this in front: ");
Debug.Log(hitFront.collider.gameObject.name);
for (var i = 0; i < obstacles.length; i++)
{
if (obstacles[i].IndexOf(hitFront.collider.gameObject.name) > -1)
{
Debug.Log("Hit in front!");
frontAvailable = false;
}
}
}
问题是,Debug.Log 显示Boundary(Clone)
. 我已包含Boundary
在数组中obstacles
。下面的代码不应该设置frontAvailable
为false吗?还是我在这里犯了错误?