- Home /
OnTriggerStay Not Working, JavaScript Help Needed
Hello, I know im making a leap in logic somewhere, But i cant find it.
What i want to do, 1. Find if the object with the LevelSelectA1 Script is touching and STAYING in the trigger, (Trigger is a seperate GameObj and yes the trigger checkbox is checked) 2. IF the Obj is triggering the trigger, Then a boolean is set true, if it exits the boolean is false. 3. IF its true and if it is clicked it plays an iTween animation! And a Select sound
Refresh me, if im wrong but don't you set up the OTHER collider with the trigger box checked? Am I possibly missing anything?
Here is the code:
var initialColor:Color;
var SelectColor:Color;
var SelectSound : AudioClip;
var FingerOverSound : AudioClip;
var menuCam : GameObject;
var A1 : GameObject;
var ReadyPOS : boolean = false;
function Start()
{
initialColor = renderer.material.color;
}
function OnMouseExit(){
renderer.material.color = initialColor;
}
function OnMouseOver(){
if (ReadyPOS) {
renderer.material.color = SelectColor;
}
}
function OnMouseEnter () {
if (ReadyPOS) {
audio.clip = FingerOverSound;
audio.Play();
}
}
function OnMouseDown () {
if (ReadyPOS) {
audio.clip = SelectSound;
audio.Play();
iTweenEvent.GetEvent(menuCam, "AreaSelectToLevelSelect").Play();
iTweenEvent.GetEvent(A1, "DiamondMoveToLevelSelectFromAreaSelect").Play();
}
}
function OnTriggerStay (other : Collider) {
ReadyPOS = true;
}
function OnTriggerExit (other : Collider) {
ReadyPOS = false;
}
Thanks for the Help! Daniel
What is the nature of the problem you're experiencing? If you put Debug.Log("Trigger stay"); in the OnTriggerStay function, is it ever being called?
@Andy$$anonymous$$artin458 No its not, BUT the rest of the code works because if i manually set the boolean to true in the inspector it works, So Whats not working here is the OnTriggerStay, Also Other just stands for any collider correct? Im going to try on collision enter too.
This is not working either,
function OnCollisionEnter (collision : Collision) {
ReadyPOS = true;
Debug.Log ("Entered");
}
function OnCollsionExit (collision : Collision) {
ReadyPOS = false;
Debug.Log ("Exited");
}
yes, other is any collider that touches your object.
@Andy$$anonymous$$artin458 I'm not getting any luck with collision enter and exit either, I have done this before, Cant seem to figure out what I'm $$anonymous$$issing? So weird! Any ideas?
Answer by AndyMartin458 · Jul 16, 2013 at 01:06 AM
Did you attach a Rigid Body to the other colliders? One of the colliders have to have a Rigid Body for that function to be called. Probably you should put one on the stationary object.
Update:
What are your objects? If you think of this example. Trigger is on the level, and the collider is a player running around. If your player and the trigger both have colliders, then the OnTriggerStay function still won't be called. You need to go to Component -> Physics -> Rigid Body and add it to the trigger or the player.
Yes i did what you said :D Thank you, Still having the issue :P
@$$anonymous$$_G the Obj With Script that moves into the collider needs to have a collider. Does it have one too?
@Andy$$anonymous$$artin458 Yes :P Sorry I didn't include that!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Changing material Color using RBG? 3 Answers
Has anyone got a Toggle key script? 3 Answers
Int and Javascript help 2 Answers