void Shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); TargetScript target = hit.transform.GetComponent <TargetScript>(); if (target != null) { nextTimeToFire = Time.time + 1f / fireRate; target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 0.5f); } }
public void Shoot() { PlayParticles(); ApplyKick(); ammo -= 1; UpdateText(); audioSource.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { TargetScript target = hit.transform.GetComponent <TargetScript>(); if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * impactForce); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 2f); } }
void TriggerExplosion() { Vector3 explosionPos = transform.position; Collider[] colliders = Physics.OverlapSphere(explosionPos, 50f); foreach (Collider hit in colliders) { Debug.Log("Collided with : " + hit.gameObject.name); TargetScript target = hit.GetComponent <TargetScript>(); if (target != null && target.canShoot) { Rigidbody rb = hit.GetComponent <Rigidbody>(); Debug.Log("Missile Hit : " + rb.gameObject.name); target.TakeDamage(missileDamage); rb.AddExplosionForce(500f, explosionPos, 50f, 10f); } } SoundManagerScript.Instance.PlaySFX(SoundManagerScript.Instance.audioClipInfoList[3].audioClipID); Destroy(this.gameObject); }
void Shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) //origin of shot, direction of shit, where to save information, input range { Debug.Log(hit.transform.name); TargetScript target = hit.transform.GetComponent <TargetScript>(); //create instance of TargetScript from the component if (target != null) { target.TakeDamage(damage); } if (hit.rigidbody != null) //test that the RaycastHit object has a rigidbody { hit.rigidbody.AddForce(-hit.normal * impactForce); //hit.normal is perpendicular to face. we need force to go into face thus negative } Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); // GameObject impactEffectObject = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); //create reference to instantiated object through GameObject // Destroy(impactEffectObject, 2f); //delete the GameObject after 2 float seconds } }
void Shoot() { muzzleFlash.Play(); RaycastHit hit; if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); TargetScript targ = hit.transform.GetComponent <TargetScript>(); if (targ != null) { targ.TakeDamage(damage); } } }
public void Shoot() { muzzle_Flash.Play(); gunShot.Play(); RaycastHit hit; if (Physics.Raycast(m_Camera.transform.position, m_Camera.transform.forward, out hit, range)) //range optional { TargetScript target = hit.transform.GetComponent <TargetScript>(); if (target != null) { target.TakeDamage(damage); } GameObject impact = Instantiate(impactFX, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impact, 2f); } }
public void Shoot() { RaycastHit hit; if (gunOverheat) { currGunHeat -= Time.deltaTime * 25f; if (currGunHeat <= 0f) { gunOverheat = false; } } else if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, fireRange) && !gunOverheat) { TargetScript target = hit.transform.GetComponent <TargetScript>(); if (target != null && target.canShoot) { if (Time.time >= nextTimeToFire) { target.TakeDamage(fireDamage); SoundManagerScript.Instance.PlaySFX(SoundManagerScript.Instance.audioClipInfoList[2].audioClipID); muzzleFlash[flashTurn].Play(); muzzleFlash[flashTurn + 2].Play(); nextTimeToFire = Time.time + 1f / fireRate; Debug.Log(hit.transform.name); flashTurn++; if (flashTurn >= 2) { flashTurn = 0; } if (hit.rigidbody != null) { hit.rigidbody.AddForce(-hit.normal * 50f); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 0.5f); currGunHeat += 15f; if (currGunHeat >= maxGunHeat) { gunOverheat = true; } if (currCharge < maxCharge && !fireMissile) { currCharge += 5f; } } } } if (currGunHeat > 0f) { currGunHeat -= Time.deltaTime * 35f; } }