private void WolfToggle1_OnValueChanged(bool value) { if (value) { wolfSelector2.Deselect(); wolfSelector1.Select(); } else { wolfSelector1.Deselect(); } }
void SelectWolf() { // raycast from mouse position in camera Ray rayClick = cam.ScreenPointToRay(Input.mousePosition); RaycastHit raycastHit; if (Physics.Raycast(rayClick, out raycastHit, Mathf.Infinity, selectionLayer.value)) { Debug.DrawRay(rayClick.origin, rayClick.direction * 100, Color.red); WolfSelector wolfSelector = raycastHit.transform.GetComponentInChildren <WolfSelector>(); if (wolfSelector == null) { Debug.Log("[PointerController] SheepSelector not found in " + raycastHit.transform.name); } else { if (currentSelectedWolf != wolfSelector) { Debug.Log("[PointerController] Sheep selected: " + raycastHit.transform.name); if (currentSelectedWolf != null) { currentSelectedWolf.Deselect(); } currentSelectedWolf = wolfSelector; currentSelectedWolf.Select(); } else { Debug.Log("[PointerController] Same sheep selected: " + raycastHit.transform.name); } } } else { /* * Debug.DrawRay(rayClick.origin, rayClick.direction * 100, Color.yellow); * * Debug.Log("[PointerController] No sheep selected"); * * if(currentSelectedWolf != null) * { * currentSelectedWolf.Deselect(); * currentSelectedWolf = null; * } */ } }