// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { mousePos1 = Camera.main.ScreenToViewportPoint(Input.mousePosition); RaycastHit rayHit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out rayHit, Mathf.Infinity, clickablesLayer)) { OnClick onClickScript = rayHit.collider.GetComponent <OnClick>(); Movement movementScript = rayHit.collider.GetComponent <Movement>(); if (Input.GetKey("left shift")) { if (onClickScript.isSelected == false) { selectedObjects.Add(rayHit.collider.gameObject); onClickScript.isSelected = true; onClickScript.Click(); movementScript.Selected(true); } else { selectedObjects.Remove(rayHit.collider.gameObject); onClickScript.isSelected = false; onClickScript.Click(); movementScript.Selected(false); } } else { ClearSelected(); selectedObjects.Add(rayHit.collider.gameObject); onClickScript.isSelected = true; onClickScript.Click(); movementScript.Selected(true); } } else { if (!Input.GetKey("left shift")) { ClearSelected(); } } } if (Input.GetMouseButtonUp(0)) { mousePos2 = Camera.main.ScreenToViewportPoint(Input.mousePosition); if (mousePos1 != mousePos2) { SelectObjects(); } } }