private void Update() { var mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition); var direction = (mouse - this.transform.position).normalized; var distance = (mouse - this.transform.position).magnitude; RaycastHit2D hit = Physics2D.CircleCast(this.transform.position, CastRadius, direction, distance, HitMask); if (hit == null || !hit) { beamToPoint.SetTargetPosition(Screen.width); } else { beamToPoint.SetTargetPosition(Vector2.Distance(hit.point, this.transform.position)); if (!collided) { collided = true; var go = hit.transform.gameObject; if (go.tag.Equals(EnemyTag)) { go.GetComponent <DamageObject>().InflictDamage(Damage); } StartCoroutine(DoImpact(hit.point)); } } }
private void Update() { var direction = GetBeamDirection(); var distance = Screen.width - this.transform.position.x; RaycastHit2D hit = Physics2D.CircleCast(this.transform.position, CastRadius, direction, distance, HitMask); if (hit == null || !hit) { beamToPoint.SetTargetPosition(Screen.width); } else { beamToPoint.SetTargetPosition(Vector2.Distance(hit.point, this.transform.position)); if (!collided) { collided = true; var go = hit.transform.gameObject; if (go.tag.Equals(HitTag)) { var goco = go.GetComponent <DamageObject>(); if (goco != null) { goco.InflictDamage(Damage); } } StartCoroutine(DoImpact(hit.point)); } } }