private void TouchStart(Touch touch, Vector2 pos) { Ray ray = Camera.main.ScreenPointToRay(touch.position); GameObject ps = Instantiate(particleSystemOnTap); ps.transform.position = ray.origin + new Vector3(0, 0, 0.05f); if (Physics.SphereCast(ray, tapRadius, out RaycastHit hit)) { Mole target = hit.transform.GetComponentInParent <Mole>(); if (target != null) { target.behaviour.HitMole(damage); OnMoleHit?.Invoke(target.behaviour.scoreOnKill); } else { OnMoleMiss?.Invoke(moleMissScore); } } else { OnMoleMiss?.Invoke(moleMissScore); } }
// DEBUG CODE private void Update() { #if UNITY_EDITOR if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); GameObject ps = Instantiate(particleSystemOnTap); ps.transform.position = ray.origin + new Vector3(0, 0, 0.05f); if (Physics.SphereCast(ray, tapRadius, out RaycastHit hit)) { Mole target = hit.transform.GetComponentInParent <Mole>(); if (target != null) { if (target.behaviour.HitMole(damage)) { OnMoleHit?.Invoke(target.behaviour.scoreOnKill); } } else { OnMoleMiss?.Invoke(moleMissScore); } } else { OnMoleMiss?.Invoke(moleMissScore); } } #endif }
public override void OnLevelEnd() { foreach (ScoreManager.ScoreAddHandler d in OnMoleHit.GetInvocationList()) { OnMoleHit -= (ScoreManager.ScoreAddHandler)d; } foreach (ScoreManager.ScoreAddHandler d in OnMoleMiss.GetInvocationList()) { OnMoleMiss -= (ScoreManager.ScoreAddHandler)d; } this.enabled = false; }