void OnTriggerEnter(Collider collision) { if (explosion != null) { GameObject newExplosion = (GameObject)Instantiate(explosion); newExplosion.transform.position = this.transform.position; Object.Destroy(newExplosion, 4.0f); } if (explodeNoise != null) { AudioSource.PlayClipAtPoint(explodeNoise, transform.position, 1.0f); } //Debug.Log ("Boom 1!"); //this.GetComponent<Rigidbody>().AddExplosionForce(explosiveForce, transform.position, explosionRadius, 1.0f, ForceMode.Impulse); Rigidbody target = collision.GetComponent <Rigidbody>(); if (target != null) { GameManager.hits++; //line below not necessary bc StandardAssets //target.AddExplosionForce (explosiveForce, transform.position, explosionRadius, 1.0f, ForceMode.Impulse); } if (collision.gameObject.tag == "Enemy") { EnemyHP hp = collision.gameObject.GetComponent <EnemyHP> (); hp.ChangeHP(-1 * explosiveForce); } Object.Destroy(this.gameObject); }
// Update is called once per frame void Shoot() { GameManager.shots++; Debug.Log("Shoot!"); lastShotTime = Time.time; RaycastHit info; if (muzzleFlash != null) { GameObject flash = Object.Instantiate(muzzleFlash, shotPoint.transform.position, Quaternion.identity); Destroy(flash, .05f); } if (machineGunSound != null) { AudioSource.PlayClipAtPoint(machineGunSound, shotPoint.transform.position, 1.0f); } //if(shotPuff != null && Physics.Raycast(this.transform.position, this.transform.forward * range,out info, range)) //the particular gun model we're using, down (up * -1) is the barrel direction if (shotPuff != null && Physics.Raycast(this.transform.position, this.transform.up * -1 * range, out info, range)) { if (info.collider.tag == "Terrain" || info.collider.tag == "Target" || info.collider.tag == "Enemy") { GameManager.hits++; Vector3 hitSpot = info.point; GameObject puff = Object.Instantiate(shotPuff, hitSpot, Quaternion.identity); Destroy(puff, 1f); if (ricochetSound != null) { AudioSource.PlayClipAtPoint(ricochetSound, hitSpot, 1.0f); } Rigidbody rb = info.collider.gameObject.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(shotForce, hitSpot, 1.0f, 0, ForceMode.Impulse); } } if (info.collider.tag == "Enemy") { EnemyHP hp = info.collider.gameObject.GetComponent <EnemyHP>(); hp.ChangeHP(-1 * shotForce); } } }