public override void Attack() { Ray raycastDir = ownerCamera.ScreenPointToRay(screenCenter); RaycastHit hitInfo; Vector3 lazerEnd = Vector3.zero; if (Physics.Raycast(raycastDir, out hitInfo, effectiveRange, raycastLayerMask)) { lazerEnd = hitInfo.point; GameObject victim = hitInfo.collider.gameObject; if (victim.CompareTag("Player")) { PlayerManager.playerToPlayerManager[victim].OnAttacked(damagePerSecond * Time.deltaTime); } } else { lazerEnd = raycastDir.origin + raycastDir.direction.normalized * effectiveRange; } lineRenderer.SetPosition(0, gunpoint.position); lineRenderer.SetPosition(1, lazerEnd); ItemUtils.Play(soundEffect); }
private void OnExplode() { Destroy(GetComponent <Rigidbody>()); foreach (var renderer in GetComponentsInChildren <MeshRenderer>()) { renderer.enabled = false; } GetComponent <Collider>().enabled = false; ItemUtils.Play(explodeSoundEffect); ItemUtils.Play(explodeViewEffect, true); ExplodeCore(); }
public void Reload(Action whenEmpty = null, Action whenReloadSucceed = null) { if (!Picked) { Debug.Log("Error: try to reload a gun that haven't been picked up."); return; } if (bulletStoreLeft <= 0) { whenEmpty?.Invoke(); return; } if (bulletInMagazine < magazineCapacity) { int shortage = magazineCapacity - bulletInMagazine; int toBeReloaded = bulletStoreLeft >= shortage ? shortage : bulletStoreLeft; bulletInMagazine += toBeReloaded; bulletStoreLeft -= toBeReloaded; ItemUtils.Play(reloadSoundEffect); whenReloadSucceed?.Invoke(); } }
public virtual void ShootSingleBullet() { if (!IsWeaponValid()) { return; } if (!UnlimitFire && IsMagazineEmpty()) { return; } Ray raycastDir = ownerCamera.ScreenPointToRay(screenCenter); Debug.DrawRay(gunpoint.position, raycastDir.direction * 1000); Vector3 bulletDir = Vector3.zero; if (Physics.Raycast(raycastDir, out hitInfo, effectiveRange, raycastLayerMask)) { bulletDir = (hitInfo.point - gunpoint.transform.position).normalized; } else { bulletDir = ownerCamera.transform.forward; } GameObject bullet = bulletPool.Next(false); bullet.transform.position = gunpoint.position; bullet.transform.rotation = Quaternion.LookRotation(bulletDir); SimpleBullet simpleBullet = bullet.GetComponent <SimpleBullet>(); if (simpleBullet != null) { simpleBullet.damage = damage; } SimpleBall simpleBall = bullet.GetComponent <SimpleBall>(); if (simpleBall != null) { simpleBall.damage = damage; } ExplosiveBall explosiveBall = bullet.GetComponent <ExplosiveBall>(); if (explosiveBall != null) { explosiveBall.centerDamage = damage; } Rigidbody rigidbody = bullet.GetComponent <Rigidbody>(); rigidbody.velocity = Vector3.zero; rigidbody.angularVelocity = Vector3.zero; bullet.SetActive(true); rigidbody.AddForce(bullet.transform.forward * bulletSpeed, ForceMode.VelocityChange); bulletInMagazine--; ItemUtils.Play(shootSoundEffect); ItemUtils.Play(shootViewEffect, true); StartCoroutine(SendBackBullet(bullet)); }