]#pragma strict
function OnTriggerEnter (myTrigger : Collider) {
if(myTrigger.gameObject.name == "First Person Controller"){
if(Input.GetMouseButton(0)){
Debug.Log("Pressed left click.");
}
}
}
I put it on a box collider, set it to is trigger, and its not working, if I take out the input,getmousebutton it will, ive tried variations on this too, any help would be great, thanks.
You are asking to, in one frame, one gazillionth of a second, to not only check the trigger enter, but also the mouse input. A user will no way ever click the exact same frame the object enters the trigger. Well he might but only one in three bazillion tries.
So, if you want input from the mouse to occur only when object is in trigger, then use onTriggerStay. If not, and you want mouse input always, use Update.
All I need is something that will play audio when the mouse is clicked and the player is in the collider, I know people generally don’t do this here, but could you write me a script to do this? Thanks, I turned off play on awake, and it doesn’t work at all now…
ok, it should in the trigger when clicked, otherwise it shouldn’t register the mouse. Really, The audio shouldn’t play unless it is within the trigger’s area, and being clicked. Thanks
still doesn’t seem to work… I put in the code several different ways, but still doesn’t work. Maybe I’m implementing it wrong, where should I put it in this code? Can you just copy and paste this with your added code?
function OnTriggerStay(other : Collider)
{
if (other.tag == "thisTagNameEtc")
{
print("other has entered and is staying");
if(Input.GetMouseButtonDown(0))
{
print("receiving mouse input");
audio.Play();
}
}
}