private void SetGroundImpactIfRequired(LazerHit hit, Vector3 position) { bool found = false; for (int i = 0; i < hit.impacts.Length; ++i) { if (hit.impacts[i].other.layer == LayerMask.NameToLayer("Ground")) { found = true; break; } } if (!found) { return; } GroundImpactEffect impact = PoolingManager.instance.Get <GroundImpactEffect>(this.lazerData.groundImpactPrefab); if (impact != null) { impact.Initialize(position, -hit.bounceNormal); impact.Launch(); } }
public override void Hit(Collider[] colliders, Vector3 pos) { this.hiting = true; LazerHit hit = new LazerHit(colliders, pos, this.lazerData.bounceLayerMask); // Callback this.onLazerHit(hit); // Impact this.SetGroundImpactIfRequired(hit, pos); // Bounce if (this.lazerData.bounce && this.bounceCount < this.lazerData.maxBounceCount) { if (hit.bounceNormal.magnitude > 0) { this.Bounce(ref hit, colliders); } } else { this.Kill(); } }
private void Bounce(ref LazerHit hit, Collider[] colliders) { Vector3 impactDirection = -direction; // Basic bounce if (this.bounceCount < this.lazerData.maxBounceCount - 1) { this.direction = this.ComputeReflectDirection(this.headRigidbody.position, this.direction, hit.bounceNormal, colliders); this.headRigidbody.velocity = this.direction * this.lazerData.speed; // Calculate mid impact between in and out bounce (this.direction has changed) impactDirection += this.direction; } // Last bounce else { // Physics foreach (Collider c in colliders) { this.ignoredCollider.Add(c); Physics.IgnoreCollision(this.headCollider, c); } if (this.lazerData.lastBounceMode == LastBounceMode.Curve) { this.StartCoroutine(this.LastBounceCurveCoroutine(this.direction)); } else if (this.lazerData.lastBounceMode == LastBounceMode.Up) { this.LastBounceUp(this.direction); } else { if (Random.Range(0, 2) == 0) { this.StartCoroutine(this.LastBounceCurveCoroutine(this.direction)); } else { this.LastBounceUp(this.direction); } } } // Effect InstantParticleEffect impact = PoolingManager.instance.Get <InstantParticleEffect>(this.lazerData.lazerImpactPrefab); if (impact != null) { impact.SetOrientation(this.headRigidbody.position, impactDirection); impact.SetColor(Color.red); impact.Launch(); } this.bounceCount++; this.hiting = false; }
private void OnHit(LazerHit other) { // Debug.Log("TO DO"); this.onHit?.Invoke(); }