// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { ClickObject tCO = hit.transform.gameObject.GetComponent <ClickObject>(); tCO?.OnClick(); //New way to avoid writing if(not null) {} } } }