- Home /
Hey guys, I want to no how to go inside an object with a collider but to still collide with it?
All I want is for my character to be able to go inside an object as if it wasn't there, but i still want the gui to show up .onCollision?
Is this Possible?
My script is:
var showGUI: boolean;
function OnCollisionEnter(coll: Collision) { if(coll.gameObject.tag == "Hint") showGUI = true; }
function OnCollisionExit(coll: Collision) { if(coll.gameObject.tag == "Hint") showGUI = false; }
function OnGUI() { if (showGUI) { GUI.Box (Rect (10,10,100,90), "Loader Menu");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), "Level 1")) {
Application.LoadLevel (1);
}
// Make the second button.
if (GUI.Button (Rect (20,70,80,20), "Level 2")) {
Application.LoadLevel (2);
}
} }
So you want it to collide with other things but not the player?
what i want is like a hint box, you can move through it but when the player touches it the gui comes up
Answer by Eagle32 · Jun 29, 2010 at 06:05 AM
It sounds like you probably want the object your character is walking into to be a trigger rather than a collider.
Quoting the BoxCollider page of the Reference Manual
Triggers
An alternative way of using Colliders is to mark them as a Trigger, just check the IsTrigger property checkbox in the Inspector. Triggers are effectively ignored by the physics engine, and have a unique set of three trigger messages that are sent out when a collision with a Trigger occurs. Triggers are useful for triggering other events in your game, like cutscenes, automatic door opening, displaying tutorial messages, etc. Use your imagination!
Then you just use OnTriggerEnter (other : Collider)
, etc rather than the OnCollision versions.
Answer by Deikkan · Jun 29, 2010 at 06:06 AM
The thing that comes to mind first is setting the collision to be a trigger.
So instead of:
function OnCollisionEnter(coll: Collision) {
if(coll.gameObject.tag == "Hint") showGUI = true; }
It would be:
function OnTriggerEnter(other: Collider) {
if(other.gameObject.tag == "Hint") showGUI = true; }
On the gameobject that contains the collider, make just the Is Trigger box is checked.
EDIT: Looks like a reply was posted while I was typing. I'll leave this up here incase it is still useful.
Your answer
Follow this Question
Related Questions
Any suggestions for a new wanted game? 0 Answers
Setting Scroll View Width GUILayout 1 Answer
How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers
C# Multiple GUI.Tooltips 2 Answers
Need help with some OnTrigger Scripting 2 Answers