Hello all.
Today I have an issue wherein I have a small script that, when the object it’s on has collided, it sets a bool to true. This works fine and I can see the bool become true upon collision, in the inspector.
I have another script, not on the same object, that has a reference to it. I’m instantiating the object with the bool script as a variable, so that I can access the specific object I’ve spawned, then I get a reference to it and check if the bool is true. If it is, it takes an action, if it isn’t, it performs a different action. Even if the bool is true, however, it always performs the other action. These are in Unityscript.
Here’s the relevant parts of the script:
function SpawnModule(pendingExit:ModuleConnector2)
{
print("Begin");
var newModule = Instantiate(newModulePrefab,this.transform.position-Vector3(0,30,0),Quaternion.identity);
print("Instantiate");
newModule.transform.parent = dungeonParent.transform;
print("Set parent");
newModuleExits = newModule.GetComponent(Module2).GetExits();
print("Get new exits");
exitToMatch = GetRandom(newModuleExits);
print("Picked exit");
MatchConnectors(pendingExit, exitToMatch);
print("Matched connectors");
print("Start yield");
yield PlaceOrDestroy(newModule);
print("End yield");
print("Finish");
}
function PlaceOrDestroy(module:GameObject):IEnumerator
{
if(module.GetComponent(Module2).collided)
{
Destroy(module);
print("Collision Detected");
isThisModuleColliding = true;
moduleAttempts++;
}
else
{
print("Module Placement Confirmed");
modulePlacementConfirmed = true;
}
}
As always, help is much appreciated.