Hello and thanks for your time.
I’m in need of knowing if triggers have a certain object in them. I’m finding that on trigger enter and exit don’t always seem to fire in my game so I thought that I could use “on trigger stay” to find out if there is a certain thing in each trigger.
The set up is this; my entire level is covered with triggers, each with a unique numbered int and a camera target attached. My player (the “TriggerCamCol”) moves through the level and as they go along the camera moves with them to show what they need to see next. If they player dies (a small bubble pops) it calls to the camera to find and look at the triggercam target that is furthest along in the sequence that has an “awake” bubble in it.
I do not destroy on instantiate anything if a bubble dies or combines with another. The excess bubbles are moved off to a far away point.
Here is the script (same script on all of them) on the triggercams (the things that say the cam should move when a bubble enters them and also sets the condition of awakeBubInTrigger so the on-pop knows what to look at:
var bubInTrigger : GameObject;
var scriptOfBubInTrigger : Bubble;
var awakeBub : boolean;
awakeBubInTrigger = false;
function OnTriggerStay(other : Collider)
{
if (other.gameObject.tag == "TriggerCamCol")
{
//get the parent gameobject, the bubble
bubInTrigger = other.transform.parent.gameObject;
//get the script attached to the parent bubble
scriptOfBubInTrigger = bubInTrigger.GetComponent(Bubble);
//set the condition the cam script needs for on pop
if (scriptOfBubInTrigger.awake == true)
{
awakeBubInTrigger = true;
}
//check to see if the cam should move to look
//if they are at start they were moved there by a spawn and we don't want to auto look on trigger
if (scriptOfBubInTrigger.movedFromStart == false){return;}
//if camera isn't looking at the camfocus it should
if (camGame.targToFrame != camFocus.transform.position)
{
camGame.FrameTargetNew(camFocus.transform.position);
Debug.Log("Cam is moving to look at# : " + trigValue);
}
}
And here’s the only way I know of of clearing the needed bool, same script. Problem is is that sometimes when lots of things are moving around alot like when bubbles are combining and being popped, the bool doesn’t seem to be set to false.
function OnTriggerExit (other : Collider)
{
if(other.gameObject.tag == "TriggerCamCol")
{
awakeBubInTrigger = false;
}
}
Here’s the script in the camera that’s called once a small bubble pops to find what the camera should look at (without something setting off a trigger):
var trigTargToFocusOn : GameObject;
var bestTrigNum : int = 0;
var highestBubVal : int = 0;
///////////////////////////////////////
function FindBestTrigerCam()
{
var triggerCamArray : GameObject[];
var triggerCamScript : TriggerCamScript;
yield WaitForSeconds(1.5); //give the bubs a moment to get in position
//find all the triggerCam objects
triggerCamArray = GameObject.FindGameObjectsWithTag ("TriggerCam");
for (var trigger : GameObject in triggerCamArray)
{
triggerCamScript = trigger.GetComponent(TriggerCamScript);
print("trigNumber: " + triggerCamScript.trigValue + " AWAKE BUB IN TRIGGER: " + triggerCamScript.awakeBubInTrigger);
if(triggerCamScript.trigValue >= bestTrigNum && triggerCamScript.awakeBubInTrigger == true)
{
bestTrigNum = triggerCamScript.trigValue;
trigTargToFocusOn = triggerCamScript.camFocus;
}
}
// Debug.Log("Best to look at ONPOP is# " + bestTrigNum);
frameTarget(trigTargToFocusOn.transform.position);
//below targToFrame for when the cam zooms back in
targToFrame = trigTargToFocusOn.transform.position;
bestTrigNum = 1;
highestBubVal = 1;
}
I hope this isn’t to garbled or spaghetti to understand the intention. Thanks for all the help guys.