- Home /
Adding an array of scripts to a class
Hi
I'm new unity and i am trying to create a reference of gameobjects and scripts i will be working with a lot rather than accessing each script and gameobject individually from multiple other scripts and gameobject which can be a nightmare to manage as the project grows.
I know that the Monobehavior type is not really an array but shouldn't it work like one?
if anyone could point me in the right direction it would be greatly appreciated.
So far i have put together the below but i cant seem to get the scripts in to scripts class variable for the assigned gameobject.
// ReferenceClass.js
#pragma strict
public class ReferenceClass
{
public var id : int;
public var gameObjectName : String;
public var description : String;
public var gameObjectTransform : Transform;
public var gameObject : GameObject;
public var scripts : MonoBehaviour[];
}
// Reference.js
#pragma strict
var ReferenceGO : ReferenceClass[];
function Start()
{
for (var i : int = 0; i < ReferenceGO.length; i++)
{
var components : Component[] = ReferenceGO[i].gameObject.GetComponents(MonoBehaviour);
for (var component : MonoBehaviour in components)
{
ReferenceGO[i].scripts += component;
Debug.Log(component);
}
}
}
Your answer
Follow this Question
Related Questions
how to build & populate an array available to all scripts on all objects? 1 Answer
Get all Scripts Attached to gameObject 1 Answer
Transport unknown amout of objects with GameObject array 0 Answers
View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers
Spawning GameObjects with help of classes --- Attaching classes to GameObjects 1 Answer