- Home /
Select Enemies(Raycast) -> Display Child Quad with circle base
I have been able to select enemies with the below raycast script, however when each enemy is selected, I want to give the user feedback which enemy is selected. (i.e. a Ring around the base of the enemy) I have been unable to create, find a solution, so asking for help / ideas to keep me going.
Currently I believe that enabling the mesh renderer on the quad will be the easiest way to do this, but I am disabling the parents renderer instead of the quad Child.
function Update()
{
if (Input.GetMouseButtonDown(1)) //Right CLick
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100))
{
Debug.DrawLine (ray.origin, hit.point);
Debug.Log (hit.collider.gameObject.name);
var es = hit.collider.gameObject.GetComponentInChildren(MeshRenderer);
es.enabled = false;
}
}
}
If you think there is a better way to do this, please let me know, or point me in the right direction.
Image of Quad Location Setup (As a Child under the Cube GameObject)
Answer by HappyMoo · Jan 01, 2014 at 07:11 AM
So you have selection quads on every unit? No need - just have one selection object that you hide/show and move around.
// show
selector.transform.position = hit.collider.gameObject.transform.position;
selector.setActive(true);
// later hide
selector.setActive(false);
Cheers Happy$$anonymous$$oo,
Worked perfectly... and love the simplicity :)
Thanks again
Your answer
Follow this Question
Related Questions
2d raycast enemy detection problem. 0 Answers
How to Stop Enemy "Shooting Through A Wall" 1 Answer
spherecast wont work 2 Answers