private void OnTriggerEnter(Collider other) { if (!particlesSpawned) //Check to make sure projectile isnt getting destroyed { //grab player movement or turret AI script Powers_PlayerMovement player = other.GetComponent <Powers_PlayerMovement>(); if (player) //check if player movement script is null. if not, then we have a player { Powers_HealthSystem playerHealth = player.GetComponent <Powers_HealthSystem>(); if (playerHealth) { playerHealth.TakeDamage(damage); } projectileSource.PlayOneShot(hitSFX); } ProjectileDestroy(); } }
private void DoAttack() { if (shootCooldown > 0) { return; //too soon } if (!wantsToTarget) { return; //player not targeting } if (!wantsToAttack) { return; //player not shooting } if (target == null) { return; //no target available } if (!CanSeeThing(target)) { return; //target not in sight } //set cooldown shootCooldown = 1 / roundPerSecond; Powers_HealthSystem targetHealth = target.GetComponent <Powers_HealthSystem>(); if (targetHealth) { targetHealth.TakeDamage(Random.Range(18, 25)); //if target has been killed, add one to the kill count. } //attack! if (pistolL && pistolLNext) { Instantiate(prefabMuzzleFlash, pistolL.position, pistolL.rotation); pistolLSource.PlayOneShot(pistolShot); } if (pistolR && !pistolLNext) { Instantiate(prefabMuzzleFlash, pistolR.position, pistolR.rotation); pistolRSource.PlayOneShot(pistolShot); } camOrbit.Shake(2); //trigger arm anim //rotates arms up: if (pistolLNext) { armL.localEulerAngles += new Vector3(-15, 0, 0); } else { armR.localEulerAngles += new Vector3(-15, 0, 0); } //move arms back: if (pistolLNext) { armL.position += -armL.transform.forward * .05f; } else { armR.position += -armR.transform.forward * .05f; } pistolLNext = !pistolLNext; }