Hi everyone,
This is my first question on these boards.
I have a scene for a RTS game that is filled with units (just basic capsules). When I click a unit I wan’t to set a plane visible that is attached as a child to the unit. All the child objects have the same name (“Plane”). The problem is when I select one unit all of the planes become visible.
The code:
#pragma strict
var selectedUnits = new Array();
var isSelected = false;
var target : Vector3;
private var selectableLayerMask = 1 << 9; //Units
private var walkableLayerMask = 1 << 10; //Ground
var hit : RaycastHit;
function Start () {
}
function Update () {
if (Input.GetMouseButtonDown(0)) {
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),hit,200,selectableLayerMask)) {
Debug.Log("Clicked on a unit");
Debug.Log(hit.collider.name);
AddUnit(hit.collider.gameObject);
isSelected = true;
}
else {
Debug.Log("Clicked on the ground");
ClearSelectionList();
}
}
if (isSelected) {
transform.Find("Plane").renderer.enabled = true;
}
}
function AddUnit (unitToAdd : GameObject) {
selectedUnits.Push(unitToAdd);
GetComponent(MoveUnit).targetPosition = transform.position;
//transform.Find("Plane").renderer.enabled = true;
}
function ClearSelectionList () {
selectedUnits.Clear();
transform.Find("Plane").renderer.enabled = false;
isSelected = false;
}
Can someone help me with this issue.
Thanks in advance.