I't trying to make it, so when the player clicks on a unit it will select it, and draw a box around the edge on it. I've been looking at other questions but I couldn't get a good answer.
Also the unit will have a specific tag like "**unit**" and you only can select that specific unit with that tag name.
So this is what I have got now...
#pragma strict
var selected : Transform;
var mask : LayerMask = -1;
var hit : RaycastHit;
function Update() {
if(Input.GetMouseButtonDown(0) && Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, Mathf.Infinity, mask.value)) {
if(hit.transform.tag == "Selected") {
hit.transform.tag = "Unselected";
selected = null;
}
else if(!selected) {
selected = hit.transform;
selected.tag = "Selected";
}
Debug.Log("clicked" + (selected? "" : " off"));
}
}
↧