Hello,
I have some prefabs on my scene that are clickable. The click works, one problem though - I can multi-select different prefabs. How can I prevent this? So I can only click one object. I was thinking about having a GetMouseDown - on raycast, and if the raycast is positioned outside the prefab, then click = false ??
Watch YouTube Video: http://www.youtube.com/watch?v=3MUCktH47MM
ClickObject:
#pragma strict
var clicked : boolean = false;
var hit : RaycastHit;
function Update() {
if(Input.GetMouseButtonDown(0) &&
collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, Mathf.Infinity)) {
clicked = !clicked;
if(tag == "Select") tag = "Unselect";
else tag = "Select";
}
}
Clickable:
function Update(){
var ExternalClickObject : ClickObject;
ExternalClickObject = gameObject.GetComponent("ClickObject");
var ExternalRadius : RadiusTexture;
ExternalRadius = gameObject.GetComponentInChildren(RadiusTexture);
if(ExternalClickObject.clicked == true){
ExternalRadius.Clicked = true;
}
else if(ExternalClickObject.clicked == false){
ExternalRadius.Clicked = false;
}
}
---- EDIT ----
I added this onto the end of ClickObject:
else if(Input.GetMouseButtonDown(0) &&
!collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, Mathf.Infinity) && clicked == true) {
clicked = !clicked;
if(tag == "Select") tag = "Unselect";
else tag = "Select";
}
}
It works - so when ever I select another turret, the current turret gets deselected. BUT it also deselects the turret when I click anywhere -- including GUIs! Which I don't want?!?!
If you could provide a script that would be great!