- Home /
Ignore Raycast not detecting collision??
I have a collider around a door detecting when the player is close enough and then showing a GUI. I have a gun that uses raycast so I put it on ignore raycast but it then ignores the collision. When I put it back to default it works fine. Is there a fix or should I just come up with a different solution?
#pragma strict
var theDoor : Transform;
var theGUI : GUISkin;
var doorIsClosed = true;
var inZone = true;
function OnTriggerEnter (theCollider : Collider)
{
if(theCollider.tag == "Player")
{
inZone = true;
}
}
function OnTriggerExit (theCollider : Collider)
{
if(theCollider.tag == "Player")
{
inZone = false;
}
}
function OnGUI ()
{
GUI.skin = theGUI;
if(inZone && doorIsClosed)
{
GUI.TextField (Rect (Screen.width/2 - 200, 500, 400, 40), "Open with O");
}
if(inZone && !doorIsClosed)
{
GUI.TextField (Rect (Screen.width/2 - 200, 500, 400, 40), "Close with O");
}
}
function Update ()
{
if (Input.GetKeyDown(KeyCode.O) && doorIsClosed && inZone)
{
DoorOpen();
}
if (Input.GetKeyDown(KeyCode.O) && doorIsClosed == false && inZone)
{
DoorClose();
}
}
function DoorOpen ()
{
theDoor.animation.CrossFade("Open");
yield WaitForSeconds(1);
doorIsClosed = false;
}
function DoorClose ()
{
theDoor.animation.CrossFade("Close");
yield WaitForSeconds(1);
doorIsClosed = true;
}
I don't quite understand the question. I also don't see anything in the script about raycasting. Are you changing something to Ignore Raycast just in the inspector, or by code?
Answer by YourGamesBeOver · Mar 13, 2014 at 07:29 PM
try making your own layer for the gun, then making your raycasts ignore that layer. that way, any Unity default raycasts (like the ones for collisions) will still act normally, but yours will properly ignore it)
I know how to make layers ignore other layers but how can make raycasts ignore a layer?
By specifically providing the Layer$$anonymous$$ask raycast is targeting. (automatically the ones left out will be ignored).
The documentation . $$anonymous$$ore specifically - the layer$$anonymous$$ask parameter.