void ShootForwardLaser(int power) { forwardParticles.Stop(); forwardParticles.Play(); effectTimer = 0f; float adjustedWidth = power * 2 * forwardBeamWidth; forwardBeamLine.startWidth = adjustedWidth * beamHitboxRatio; forwardBeamLine.endWidth = adjustedWidth * beamHitboxRatio; forwardBeamLine.enabled = true; forwardBeamLine.positionCount = 2; forwardBeamLine.SetPosition(0, transform.position + shootDirection.up); forwardBeamLine.SetPosition(1, shootDirection.up * range + transform.position); RaycastHit2D[] hits = (Physics2D.CircleCastAll(transform.position, adjustedWidth, shootDirection.up, range, shootableMask)); foreach (RaycastHit2D hit in hits) { if (hit.collider != null) { Debug.Log(hit.collider); GameObject hitTarget = hit.rigidbody.gameObject; Destroyable targetDestroyable = hitTarget.GetComponent <Destroyable>(); if (targetDestroyable != null) { targetDestroyable.TakeDamage(laserDamage); } } } }
void OnTriggerEnter2D(Collider2D hitInfo) { Destroyable destroyable = hitInfo.GetComponent <Destroyable>(); if (destroyable != null) { destroyable.TakeDamage(damage); } Destroy(gameObject); }
private void OnTriggerEnter2D(Collider2D other) { Destroyable destroyableObject = other.GetComponent <Destroyable>(); if (destroyableObject != null) { //get damage object can do if (destroyableObject.ColorSide != bulletColorSide) { destroyableObject.TakeDamage(damage); } else { return; } } OnBulletDestroy(gameObject); }
void Shoot() { leftLine.SetPosition(0, left.position); rightLine.SetPosition(0, right.position); RaycastHit hit; if (Physics.Raycast(cockpitCam.transform.position, cockpitCam.transform.forward, out hit)) { leftLine.SetPosition(1, hit.point); rightLine.SetPosition(1, hit.point); Destroyable target = hit.transform.GetComponent <Destroyable>(); if (target != null) { if (target.health > 0.0f) { GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(effect, 4f); target.TakeDamage(damage); } else { GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal)); effect.transform.localScale = new Vector3(200, 200, 200); Destroy(effect, 4f); target.Kill(); explosion.Play(); } } else { GameObject effect = Instantiate(impact, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(effect, 4f); } Debug.Log(hit.transform.name); } else { leftLine.SetPosition(1, cockpitCam.transform.position + (cockpitCam.transform.forward * 1000)); rightLine.SetPosition(1, cockpitCam.transform.position + (cockpitCam.transform.forward * 1000)); } }