- Home /
The question is answered, right answer was accepted
Raycasting with LayerMask gives me a bce0023
hello again: I have a problem casting a ray, looking up other bce0023 seem mostly caused by typo erros, but i cannot find what is wrong with the following script. i even tried creating the ray and all the variables inside the case, but it gives me the same error:
Assets/_Weapons/Scripts/PlayerControls.js(80,44): BCE0023: No appropriate version of 'UnityEngine.Physics.Raycast' for the argument list '(UnityEngine.Ray, System.Type, float, int)' was found.
if(Input.GetMouseButtonUp(0)){
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit = RaycastHit;
var layerMask = 1 << 8; //ignoring all but the gui clickable layer
switch(mouseState){
case MouseState.select :
soundPlayer.PlaySound(soundClick,0,0);
if (Physics.Raycast(ray,hit,Mathf.Infinity,layerMask)) {
if(!hit.transform.tag=="Environment"){
selected = hit.transform.parent.transform; //assigning clicked object
}
else{
Instantiate(deselectParticles,hit.point,Quaternion.Identity);
selected = null; //deselecting since we hit environment
}
UpdateGUI();
}
break;
I am always happy if you have a better way of coding this. I am trying to handle all the user input via switch and a mouseState that can change to different actions, depending on what the mouseCursor is.
Answer by Eric5h5 · Jun 15, 2012 at 08:15 PM
As the error message says, you're giving it a Ray, Type, float, and int, but if you look at the docs, you see you need a Ray, RaycastHit, float, and int. Writing "var hit = RaycastHit;" assigns a Type to the hit variable, but you don't want to assign anything to it, you just want to declare the type, namely "var hit : RaycastHit".
see i knew i had a typo in there!!! thank you for the quick reply Eric!
Follow this Question
Related Questions
SphereCast doesn't work with a layerMask 1 Answer
unity raycast layers in Multiplayer 0 Answers
Layer Mask on raycast2d not working? 1 Answer
I have a problem with Layermask Unity2D 0 Answers
layers not ignored by raycast 1 Answer