private void RaycastNewTarget() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); LayerMask targetMask = LayerMask.GetMask("Targetable"); if (Physics.Raycast(ray, out hit, 100.0f, targetMask, QueryTriggerInteraction.Collide)) { if (myTarget != null) { myTarget.GetComponentInChildren <Projector>().enabled = false; myTarget.GetComponent <Health>().EventOnHealthChange -= ChangeTargetHudHealth; if (myTarget.GetComponent <Resource>() != null) { myTarget.GetComponent <Resource>().EventOnResourceChange -= ChangeTargetHudResource; } } GameObject target = FindParentWithNetworkIdentity(hit.collider.transform.gameObject); myTarget = target; CmdSetTarget(target); myTarget.GetComponentInChildren <Projector>().enabled = true; SetTargetHUD(); } else { if (myTarget != null) { myTarget.GetComponentInChildren <Projector>().enabled = false; myTarget.GetComponent <Health>().EventOnHealthChange -= ChangeTargetHudHealth; if (myTarget.GetComponent <Resource>() != null) { myTarget.GetComponent <Resource>().EventOnResourceChange -= ChangeTargetHudResource; } } CmdSetTarget(null); myTargetHUD.Hide(); myShouldAutoAttack = false; } }