private void Shoot() { muzzleFlash.Play(); audioMedic.pitch = Mathf.Max(Time.timeScale, .1f); audioMedic.Play(); if (Time.timeScale > .9f) { RaycastHit hit; if (Physics.Raycast(_camera.transform.position, _camera.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); GameObject flashGO = Instantiate(flash, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(flashGO, 3f); IShootable shootable = hit.transform.GetComponent <IShootable>(); if (shootable != null) { shootable.OnShot(); } } } else { GameObject ob = Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation); ob.SetActive(true); } }
public override void OnUse() { if (cooldown > 0) { return; } cooldown = cooldownTime; Vector2 targetPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 direction = (targetPoint - (Vector2)barrel.position).normalized; if (Vector2.Dot(direction, Vector2.right * transform.localScale.x) <= maxDot) { return; } triggerCollider.enabled = false; RaycastHit2D hit = Physics2D.Raycast((Vector2)barrel.position, direction, 50f, GameManager.ins.shootableLayers); triggerCollider.enabled = true; if (hit.collider != null) { ShowGunLine(hit.point); IShootable shotObject = hit.collider.gameObject.GetComponent <IShootable>(); if (shotObject != null) { shotObject.OnShot(); } } }
void OnCollisionEnter(Collision other) { Debug.Log(other); GameObject flashGO = Instantiate(flash, other.contacts[0].point, Quaternion.LookRotation(other.contacts[0].normal)); Destroy(flashGO, 3f); IShootable shootable = other.gameObject.GetComponent <IShootable>(); if (shootable != null) { shootable.OnShot(); } Destroy(gameObject); }
private void OnTriggerEnter2D(Collider2D other) { IShootable shootable = other.GetComponent <IShootable>(); if (shootable != null) { if (shootable.GetTeam() != team) { animator.SetTrigger(Hit); shootable.OnShot(this); } return; } speed = 0; animator.SetTrigger(Hit); }