Hello,
I’m pretty new to using arrays… I am creating object clones and trying to store them into array called colors… I’ve googled and looked up for some answers but with no luck. Those are the codes I got from internet…
public var colors : GameObject[];
var startPoint: Vector3;
var endPoint: Vector3;
var numObjects: int;
var objects: Transform[];
function addToArray ( obj : GameObject )
{
colors += [obj];
}
function Start ()
{
for ( var s = 0 ; s < numObjects; s++ )
{
var newObj = Instantiate(objects[ Random.Range( 0 , objects.Length ) ] );
newObj.position = Vector3.Lerp( startPoint , endPoint, ( s * 1.0 ) / ( numObjects - 1 ) );
addToArray( newObj );
}
}
… But it gives me error when I try adding the object to array…
Player.js(49,35): BCE0017: The best
overload for the method
‘Player.addToArray(UnityEngine.GameObject)’
is not compatible with the argument
list ‘(UnityEngine.Transform)’.
Could anyone please fix this problem and explain what I did wrong? Thank you in advance.