Hi guys! I am creating a game in which you have to click building, UI element will show up and stuff, and when this 'building' is selected and anything but UI element is clicked(small box with buttons and statistics, it's not the case tho), the building got deselected (inside it's script value isSelected is changed to false). And if you click other building, the first one becomes deselected and the new one selected (I achieved this by making prevBuilding variable and filling this value with activeBuilding value as a first step of building selection method) But I have two problems here: 1. On first click in-game none of the buildings gets selected (because prevBuilding value is empty I think) and 2. Everything works fine as long as I don't click something different than the 'building' game object. When I click let's say ground, two buildings are selected and I can't deselect any of them. Here's my script Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseSelection : MonoBehaviour { private GameObject previousBuilding; private GameObject activeBuilding; private void Update() { if (Input.GetKeyDown("mouse 0")) { RaycastHit selectionRaycastHit; Ray selectionRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(selectionRay, out selectionRaycastHit, 100f)) { previousBuilding = activeBuilding; Debug.Log("it works!"); Selection selection = selectionRaycastHit.collider.GetComponent<Selection>(); activeBuilding = selectionRaycastHit.collider.gameObject; if (selection != null) { if (selection.isSelected == false) OnBuildingSelect(selection); //else //OnBuildingDeselect(selection); } } } } private void OnBuildingSelect(Selection sel) { Debug.Log("select"); Selection prevSel = previousBuilding.GetComponent<Selection>(); prevSel.isSelected = false; sel.isSelected = true; } private void OnBuildingDeselect(Selection sel) { Debug.Log("deselect"); sel.isSelected = false; activeBuilding = null; } } Btw Selection class contains only simple script that checks if isSelected is true then the cube changes material (for playtesting purposes). Thanks for help, Siudinho.