Instantiate Prefabs. Errors.

Hey all, I’m working on a game for a class and I’m so stuck. I want to spawn objects every so often from a random array of points. This is the code that I have so far and I keep getting the error:

MissingMethodException: Method not found: ‘UnityEngine.GameObject.GetComponent’.
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey14.<>m__7 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object args, System.Type scriptBaseType)
Spawn.Start () (at Assets/Scripts/Spawn.js:5)

No idea. This is the code though(it’s from another source but I can’t find anything else about it or how to fix it):

var vecArray:Vector3[];
var top:int;
var Rectangle:Transform;
function Start(){
    vecArray = GameObject.FindGameObjectsWithTag("SpawnPoint").GetComponent(Transform).position;
    top = vecArray.Length;
    InvokeRepeating("CreateObject",01f,3.0f);
}
function CreateObject(){
    Instantiate(Rectangle,vecArray[Random.Range(0,top)],Quaternion.identity);
}

FindGameObjectsWithTag returns an array of GameObjects, so your method of assigning vecArray can’t work–Transform.position is not a property of an array. What you should do instead is create a Vector3 array with the same number of elements as the array returned by FindGameObjectsWithTag, then iterate through the GameObject array and get the transform.position from each one, and assign that to the appropriate slot in the Vector3 array. (Also you don’t need “GetComponent(Transform)”, you can just write “transform”.)

Hello,

I’m not familiar with Boo, but I wrote some similar code in C#. Might be of some use

This will get any Gameobjects Tagged as “SpawnPoint”

// Initialise the array with 20 elements
spawnPointArray = new GameObject[20];
		
// Populate the array with the Spawn Point Gameobjects
spawnPointArray = (GameObject[])GameObject.FindGameObjectsWithTag("SpawnPoint");

This will spawn (or instantiate) the Prefab enemy at the point. You could set up a timer in update, put what’s below in a method, and call it when the timer expires.

// Get a random number and access that position on the spawn point array
int spawnPointNumber = Random.Range(1, 20);
Vector3 activeSpawn = spawnPointArray[spawnPointNumber].transform.position;
		
// Instantiate the enemy 
Instantiate(enemy, activeSpawn, Quaternion.identity);