I have 4 different prefabs, that each will be duplicated in any given level various times, and each has its condition to be “activated”.
When all prefabs are activated (each in their own way), the level is finished. This sounds like a simple problem, but can’t get my head around on finding a solution to do this in a way that I can repeat the code in every new level I create.
I was trying to use GameObject.FindObjectsWithTag, but then don’t know how to check if the boolean on all of them is true.
I’m a noob in coding, so any help is greatly appreciate! (And I’m guessing there is a extremely easy way to do it )
Further to that, on the same lines as the previous problem, I need to create sub-groups, where I might have 8 objects in total, but I need to trigger an event when 4 specific objects are then “activated”.
I can’t use tags as these are already in use by the previous solution and I can’t tag a single object with more than one tag.
GameManager.js
static var groupCount : int[];
static function AddGroupMember( group : int ) {
if ( group >= groupCount.length ) {
var x = new Array( groupCount );
while ( x.length <= group ) {
x.Add(0);
}
groupCount = x.ToBuiltin(int);
}
groupCount[ group ] += 1;
}
static function GroupMemberDestroyed( group : int ) {
groupCount[ group ] -= 1;
if ( groupCount[group] <= 0 ) GroupDestroyed( group );
}
static function GroupDestroyed( group : int ) {
// stuff
}
and
GroupedObject.js
var myGroup : int;
function Start() {
GameManager.AddGroupmember( myGroup );
}
function Destroyed() {
GameManger.GroupMemberLost( myGroup ); // or "this" if you need the groupedobject info
}
There’s probably some efficientizing to do in there too.
Before I saw your reply, I had an idea of doing more or less the same as your first suggestion, but tagging a child object and activating it when the objects was visible to countdown.