anybody knows why loops doesnot work?
altough the car enter the trigger,"if loop " doesnot recognize array
var test : GameObject;
function OnTriggerEnter(collision : Collider)
{
if (collision.gameObject.name==test[1])
{
//do something
}
anybody knows why loops doesnot work?
altough the car enter the trigger,"if loop " doesnot recognize array
var test : GameObject;
function OnTriggerEnter(collision : Collider)
{
if (collision.gameObject.name==test[1])
{
//do something
}
Thats not a loop, your only accessing the 2nd item (index 1). If you want to loop through all of them then do something like this:
foreach( var item in test )
if( item.name == collision.gameObject.name )
// Do something
A standard for loop would be like this:
for( int i = 0; i < test.Length; ++i )
if( test*.name == collision.gameObject.name )*
// Do something