protected void Fire() { if (hammer.cocked && !barrel.isOut) { // check cylinder to be fired, check filled for fire / blank bool firedBullet = barrel.GetCurrentCylinder().Expel(); hammer.Reset(); if (firedBullet) { muzzleFlash.Flash(); Camera.main.GetComponent <CameraBehavior>().Shake(); audioSource.PlayOneShot(SoundManager.LoadSoundClip("shot" + Random.Range(1, 3))); Vector3 dir = (body.sightPoint - Camera.main.transform.position) * 100f; Debug.DrawRay(body.sightPoint, dir, Color.red, 100f); int layerMask = 1 << LayerMask.NameToLayer("Enemies"); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(body.sightPoint, dir, out hit, 100f, layerMask)) { SlimeEnemy slime = hit.transform.gameObject.GetComponent <SlimeEnemy>(); slime.Damage(100); score += 1; } } else { audioSource.PlayOneShot(SoundManager.LoadSoundClip("dryfire")); } } }
void Update() { if (shootTimer < shootDelay) { shootTimer += Time.deltaTime; } if (Input.GetAxis(shootAxis) > 0 && shootTimer >= shootDelay && ammoCount > 0) { // Point to spawn the bullet at. // How we do this: We assume the shooter object has certain points // which are its children; we then pick the first child and shoot from that. Transform spawnTransform = transform.GetChild(currentSpawnChild); currentSpawnChild = (currentSpawnChild + 1) % transform.childCount; // move to next child Vector3 spawnPt = spawnTransform.position; // Rotation to spawn the bullet towards. // If the targetter has a target, aim at that. // Otherwise, just aim 'forward'. Quaternion quaternion; if (targetter.currentTarget != null) { Vector3 targetPt = targetter.currentTarget.transform.position; targetPt.y += 1; Quaternion oldRotation = spawnTransform.rotation; spawnTransform.LookAt(targetPt); quaternion = spawnTransform.rotation; spawnTransform.rotation = oldRotation; } else { quaternion = spawnTransform.rotation; } Instantiate(spwnObj, spawnPt, quaternion); shootTimer -= shootDelay; ammoCount -= 1; // Try for muzzle flash // TIDYME: 2018-07-07: Use Property, rather than GetComponentInChildren MuzzleFlash mflash = spawnTransform.gameObject.GetComponentInChildren <MuzzleFlash>(); if (mflash != null) { mflash.Flash(); } } }
public void Fire() { m_frequency = m_turretAnimator.speed; foreach (Hand hand in m_currentHands) { IndexInput input = hand.GetComponent <IndexInput>(); if (input.TriggerPull > m_minTriggerPull) { if (m_sphereCastFiring) { if (Physics.SphereCast(m_fireTransform.position, m_spherecastSize, m_fireTransform.forward, out RaycastHit hitInfo, m_sphereCastDistance, m_spherecastLayerMask)) { Debug.Log(hitInfo.transform.name); Health health = hitInfo.transform.gameObject.GetComponent <Health>(); if (health != null) { Debug.Log(hitInfo.transform.name + ": damaged"); health.TakeDamage(15); } } GameObject _projectile = Instantiate(m_projectilePrefab, m_fireTransform); _projectile.transform.SetParent(null); if (hand.handType == SteamVR_Input_Sources.RightHand) { Pulse(m_delayTimer, m_duration, m_frequency, m_amplitude, SteamVR_Input_Sources.RightHand); } if (hand.handType == SteamVR_Input_Sources.LeftHand) { Pulse(m_delayTimer, m_duration, m_frequency, m_amplitude, SteamVR_Input_Sources.LeftHand); } //Pulse(1.0f, 150.0f, 75.0f, input); StartCoroutine(m_muzzelFlash.Flash()); if (m_firingSounds.Count != 0) { m_audioSource.clip = m_firingSounds[Random.Range(0, m_firingSounds.Count - 1)]; m_audioSource.Play(); } } } } }
public override void Attack() { base.Attack(); muzzleFlash.Flash(); GameObject projectile = Instantiate( projectilePrefab, FiringPosition, transform.rotation ) as GameObject; Vector3 aimingDirection = FiringDirection; float vOffset = Random.Range(-verticleSpray, verticleSpray); aimingDirection = Quaternion.AngleAxis(vOffset, Vector3.right) * aimingDirection; float hOffset = Random.Range(-horizontalSpray, horizontalSpray); aimingDirection = Quaternion.AngleAxis(hOffset, Vector3.up) * aimingDirection; DamageInfo damageInfo = new DamageInfo(damage, DamageType.Puncture, owner); projectile.GetComponent <Projectile>().Init(owner, aimingDirection, range, damageInfo); rounds--; if (weaponUI) { weaponUI.Rounds = rounds; } if (rounds <= 0) { EjectMagazine(); } if (weaponFlash) { weaponFlash.color = Color.Lerp(Color.white, Color.yellow, Random.value); weaponFlash.enabled = true; weaponFlash.intensity = 5; } }
void Fire() { foreach (Hand hand in currentHands) { IndexInput input = hand.GetComponent <IndexInput>(); if (input.TriggerPull > minTriggerPull) { //if(sphereCastFireing) //{ // if(Physics.SphereCast(fireTransform.position, sphereCastSize, fireTransform.forward, out RaycastHit hitInfo, sphereCastDistance, sphereCastLayerMask)) // { // Debug.Log(hitInfo.transform.name); // } //} //GameObject _projectile = Instantiate(projectile, fireTransform); StartCoroutine(muzzleFlash.Flash()); } } }
public void Fire() { if (Physics.SphereCast(m_fireTransform.position, m_spherecastSize, m_fireTransform.forward, out RaycastHit hitInfo, m_sphereCastDistance, m_spherecastLayerMask)) { Debug.Log(hitInfo.transform.name); Health health = hitInfo.transform.gameObject.GetComponent <Health>(); if (health != null) { health.TakeDamage(m_damageAmount); } } GameObject _projectile = Instantiate(m_projectilePrefab, m_fireTransform); _projectile.transform.SetParent(null); StartCoroutine(m_muzzelFlash.Flash()); if (m_firingSounds.Count != 0) { //m_audioSource.clip = m_firingSounds[Random.Range(0, m_firingSounds.Count-1)]; //m_audioSource.Play(); } m_audioSource.Play(); }
public void FireVisual() { muzzle.Flash(); }