/** * Fire the gun into the scene, or click make a click if no bullets. */ public void FireGun() { // pseudo code: // Is there any bullets left? // if not, click, and do not fire. return. // otherwise play a fire sound effect // raycast from either mouse position or the center position of this object into the scene to see if anything is hit. // run the function in the hitable object to react to the hit. if (shotPointer < 6 && Time.time > nextFire) { isReloading = false; nextReload = 0.0f; nextFire = Time.time + fireDelay; AudioClip thisSound = shotSounds[Random.Range(0, shotSounds.Length)]; objectAudio.PlayOneShot(thisSound, 0.35f); wasLastClipWarn = false; Renderer rend = BulletUIChildren[shotPointer].GetComponent <Renderer>(); rend.enabled = false; shotPointer++; RaycastHit eHit; //Check for weak point hit, then check for normal hit if (Physics.Raycast(scopeCamera.transform.position, Vector3.forward, out eHit, 25f, weakPointMask, QueryTriggerInteraction.Ignore)) { //weakpoint hitbox is a child of enemy, get parent first EnemyHandler eScript = eHit.transform.parent.transform.GetComponent <EnemyHandler>(); eScript.weakPointHit(); if (multi < 5) { multi++; } thisCombo++; if (thisCombo > topCombo) { topCombo = thisCombo; } score = score + (critHitValue * multi); Cursor.SetCursor(critCursorTexture, hotSpot, cursorMode); removeHitMarker = Time.time + hitMarkerDelay; checkCursor = true; hitSource.PlayOneShot(critSound, 1f); spawnCounter++; } else if (Physics.Raycast(scopeCamera.transform.position, Vector3.forward, out eHit, 25f, enemyMask, QueryTriggerInteraction.Ignore)) { if (eHit.transform.GetComponent <EnemyHandler>() == null) { if (eHit.transform.tag == "HealthPack") { foreach (GameObject thisPack in HealthUIChildren) { Renderer healthRend = thisPack.GetComponent <Renderer>(); healthRend.enabled = true; } hitsTaken = 0; AudioSource packAudio = eHit.transform.GetComponent <AudioSource>(); packAudio.PlayOneShot(packAudio.clip); Renderer packRend = eHit.transform.GetComponent <Renderer>(); packRend.enabled = false; eHit.transform.gameObject.layer = 10; } else if (eHit.transform.tag == "Supercharger") { AudioSource packAudio = eHit.transform.GetComponent <AudioSource>(); packAudio.PlayOneShot(packAudio.clip); Renderer packRend = eHit.transform.GetComponent <Renderer>(); packRend.enabled = false; eHit.transform.gameObject.layer = 10; chargeExpire = Time.time + chargeDuration; isCharged = true; reloadDelay = 0.12f; fireDelay = 0.25f; nextReload = 0.0f; foreach (GameObject thisBullet in BulletUIChildren) { Renderer bRend = thisBullet.GetComponent <Renderer>(); bRend.material.color = Color.red; } } else if (eHit.transform.tag == "ScreenClear") { AudioSource packAudio = eHit.transform.GetComponent <AudioSource>(); packAudio.PlayOneShot(packAudio.clip); Renderer packRend = eHit.transform.GetComponent <Renderer>(); packRend.enabled = false; eHit.transform.gameObject.layer = 10; EnemyHandler eScript; foreach (Transform thisEnemy in enemySpawnParent.transform) { eScript = thisEnemy.gameObject.GetComponent <EnemyHandler>(); if (!eScript.isDead) { eScript.weakPointHit(); score = score + critHitValue; } } } } else { EnemyHandler eScript = eHit.transform.GetComponent <EnemyHandler>(); eScript.normalHit(); multi = 0; score = score + normalHitValue; Cursor.SetCursor(hitCursorTexture, hotSpot, cursorMode); removeHitMarker = Time.time + hitMarkerDelay; checkCursor = true; hitSource.PlayOneShot(hitSound, 2f); thisCombo = 0; } } else { multi = 0; thisCombo = 0; } } else if (shotPointer == 6 && Time.time > nextFire) { if (!objectAudio.isPlaying || (objectAudio.isPlaying && !wasLastClipWarn)) { objectAudio.PlayOneShot(objectAudio.clip, 0.5f); wasLastClipWarn = true; } } }