- Home /
Problem with raycast
Hello! I'm having a problem when I try to spam creatures. I have some buttons to select which creature you want to invoque and after you have to press the right mouse button on the map to invoque it (that's working perfectly). I have some units that attack those creatures using raycasthit to do damage.
The problem that I have is when the click of the mouse falls in one of those raycast, because the mouse is not hitting the terrain and then the creature can't be invoqued.
How can I invoque a creature although the mouse clicks on a raycast?
(some of that raycast are fields of vision of some structures and other players)
I hope the question be well formulated.
Thank you all!
I have a fuzzy idea of what you are asking. One solution is to use the Collider from the terrain and do a Collider.Raycast() ins$$anonymous$$d of Physics.Raycast(). Collider.Raycast() cast the ray against a single specific collider rather than the whole scene. This would allow you to cast a ray against the terrain without worrying about hitting any other objects.
I'm sorry @robertbu nut I have the same problem. Here's the code I used to:
function Update () {
guiZerebros.text= "Zerebros: " + zerebros;
if(Input.Get$$anonymous$$ouseButtonDown(0)) {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(collider.Raycast(ray,hit,300.0) && zerebros >= construccionCost ) {
Instantiate(construccion,Vector3(hit.point.x,0.6,hit.point.z),Quaternion.identity);
switch(construccion) {
case RASTREATOR:
zerebros -= costeRastreator;
break;
case ZO$$anonymous$$BIE$$anonymous$$ALO:
zerebros -= costezombie$$anonymous$$alo;
break;
default: print("ninguno aplica!");
break;
}
}
}
}
Those fields in red are composed by raycast and inside the fields in red I can't spawn any creature. Thanks in advance!!
Your answer
Follow this Question
Related Questions
problem with touch android 0 Answers
Raycast 360 degree check? 1 Answer
Raycast detects only on one side problem? 0 Answers
Reload FPS Animation Not Playing (Javascript) 1 Answer
Raycast Delay 3 Answers