private void CreateHitVFX() { GameObject vfx = PrefabManager.instance.InstantiatePrefabByName("CFX3_Hit_SmokePuff"); vfx.transform.position = transform.position + Vector3.up * 0.5f; vfx.AddComponent <DestroyAfterTimeElapsed>().time = 1f; GameObject vfx2 = PrefabManager.instance.InstantiatePrefabByName("CFX_Hit_C White"); vfx2.transform.position = transform.position + Vector3.up * 0.5f; vfx2.AddComponent <DestroyAfterTimeElapsed>().time = 1f; if (GetComponent <PlayerController>() != null) { // TODO bdsowers : The hit flash is wonky on Mac; disabling for now, // but we should fix it properly if (Application.platform != RuntimePlatform.OSXPlayer) { HitFlash hitFlash = GameObject.FindObjectOfType <HitFlash>(); hitFlash.Flash(); } if (Game.instance.playerData.Gender() == 0) { Game.instance.soundManager.PlaySound("male_hit"); } else { Game.instance.soundManager.PlaySound("female_hit"); } } }
//=================================================== // UNITY METHODS //=================================================== /// <summary> /// Awake. /// </summary> void Awake() { health = GetComponent<Health>(); hitFlash = GetComponent<HitFlash>(); startingHealth = health.HealthValue; a = footman.GetComponent<Animator>(); }
void Start() { m_audioManager = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <AudioManager>(); m_damageManager = GameObject.FindGameObjectWithTag("DamageManager").GetComponent <DamageManager>(); m_cameraController = Camera.main.GetComponent <CameraController>(); m_hitFlash = GetComponent <HitFlash>(); m_currentHealth = m_maxHealth; }
public BaseWeapon(float damage, float shootRate, HitFlash hitFlash, PlayerHealth playerOneHealth, PlayerHealth playerTwoHealth) { this.damage = damage; this.shootRate = shootRate; this.currentShootInverval = 0.0f; this.hitFlash = hitFlash; this.playerOneHealth = playerOneHealth; this.playerTwoHealth = playerTwoHealth; }
void Start() { m_currentHealth = m_maxHealth; m_HeartsHealthVisual.InitHealth(m_currentHealth); m_cameraController = Camera.main.GetComponent <CameraController>(); m_audioManager = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <AudioManager>(); m_hitFlash = GetComponent <HitFlash>(); m_playerCollider = GetComponent <BoxCollider2D>(); }
public DroneWeapon(float damage, float shootRate, PlayerHealth playerOneHealth, PlayerHealth playerTwoHealth, GameObject droneFireSound, HitFlash hitFlash, GameObject[] muzzleFlash, Animator droneAnimator) : base(damage, shootRate, hitFlash, playerOneHealth, playerTwoHealth) { this.droneFireSound = droneFireSound; this.muzzleFlashInterval = 0.0f; this.muzzleFlash = muzzleFlash; this.droneAnimator = droneAnimator; }
public Sniper(float rotationSpeed, GameObject[] activationColliders, GameObject sniper, float shootDelay, float speedPenalty, float damage, AudioSource sniperFire, Vector3[] colorSet) : base(rotationSpeed, sniper) { this.sniper = sniper; this.playerOne = GameObject.FindGameObjectWithTag("PlayerOne"); this.playerTwo = GameObject.FindGameObjectWithTag("PlayerTwo"); playerOneHealth = playerOne.GetComponent <PlayerHealth>(); playerOneLifeHandler = playerOne.GetComponent <PlayerLifeHandler>(); PlayerSlow playerOneSlow = playerOne.GetComponent <PlayerSlow>(); playerTwoHealth = null; playerTwoLifeHandler = null; PlayerSlow playerTwoSlow = null; if (playerTwo != null) { playerTwoHealth = playerTwo.GetComponent <PlayerHealth>(); playerTwoSlow = playerTwo.GetComponent <PlayerSlow>(); playerTwoLifeHandler = playerTwo.GetComponent <PlayerLifeHandler>(); } HitFlash hitFlash = GameObject.FindGameObjectWithTag("GameManager").GetComponent <HitFlash>(); colliders = new BoxCollider[activationColliders.Length]; for (int i = 0; i < activationColliders.Length; ++i) { colliders[i] = activationColliders[i].GetComponent <BoxCollider>(); } Random.seed = System.Environment.TickCount; lineRenderer = sniper.GetComponent <LineRenderer>(); currentTarget = Vector3.zero; previousDirection = new Vector3(1000f, 1000f, 1000f); inverseIgnoredColliders = ~(1 << LayerMask.NameToLayer("SniperCollider") | 1 << LayerMask.NameToLayer("Checkpoint") | 1 << LayerMask.NameToLayer("Drone")); targetedPlayer = 0; heightOffset = new Vector3(0, playerOne.GetComponent <CharacterController>().center.y, 0); transformScale = new Vector3(1.0f / sniper.transform.lossyScale.x, 1.0f / sniper.transform.lossyScale.y, 1.0f / sniper.transform.lossyScale.z); sniperWeapon = new SniperWeapon(damage, shootDelay, playerOneHealth, playerTwoHealth, playerOneSlow, playerTwoSlow, sniperFire, hitFlash, speedPenalty); Vector3 rgb = colorSet[ColorIndex(shootDelay, damage, speedPenalty)]; Color threatColor = new Color(rgb[0] / 255f, rgb[1] / 255f, rgb[2] / 255f, 1); sniper.GetComponent <LineRenderer>().SetColors(threatColor, threatColor); if (colliders.Length > 0) { GenerateRandomTarget(); } }
public SniperWeapon(float damage, float shootRate, PlayerHealth playerOneHealth, PlayerHealth playerTwoHealth, PlayerSlow playerOneSlow, PlayerSlow playerTwoSlow, AudioSource sniperFireSound, HitFlash hitFlash, float speedPenalty) : base(damage, shootRate, hitFlash, playerOneHealth, playerTwoHealth) { this.playerOneSlow = playerOneSlow; this.playerTwoSlow = playerTwoSlow; this.sniperFireSound = sniperFireSound; this.speedPenalty = speedPenalty; }
public override bool Fire(Vector3 position, Vector3 direction, float range, int ignoreLayer) { bool returnValue = false; CurrentShootInverval += Time.deltaTime; RaycastHit hit; // Fire towards player if (CurrentShootInverval > ShootRate && Physics.Raycast(position, direction, out hit, range, ignoreLayer)) { sniperFireSound.Play(); if (hit.collider.tag == "PlayerOne") { Debug.Log("Player one shot"); if (PlayerOneHealth.DeductHP(Damage)) { returnValue = true; } else { playerOneSlow.ApplyGeneralSlow(0.0f, 8.0f, 0.1f, speedPenalty); HitFlash.FlashCamera(1); } } else if (hit.collider.tag == "PlayerTwo") { Debug.Log("Player two shot"); if (PlayerTwoHealth.DeductHP(Damage)) { returnValue = true; } else { playerTwoSlow.ApplyGeneralSlow(0.0f, 8.0f, 0.1f, speedPenalty); HitFlash.FlashCamera(2); } } CurrentShootInverval -= ShootRate; } return(returnValue); }
public override bool Fire(Vector3 position, Vector3 direction, float range, int ignoreLayer) { bool returnValue = false; CurrentShootInverval += Time.deltaTime; muzzleFlashInterval += Time.deltaTime; // Turn off muzzle flash light if (muzzleFlashInterval > 0.05f) { foreach (GameObject muzzle in muzzleFlash) { muzzle.light.enabled = false; } } // Turn off shoot animation state if shoot animation is complete if (!droneAnimator.GetCurrentAnimatorStateInfo(1).IsName("Shoot")) { droneAnimator.SetBool("Shooting", false); } if (CurrentShootInverval > ShootRate) { Debug.DrawLine(position, position + (direction * range), Color.red, 2.0f, false); CurrentShootInverval -= ShootRate; droneAnimator.SetBool("Shooting", true); // Shoot sound GameObject.Instantiate(droneFireSound, position, Quaternion.identity); // Start muzzle flash effect foreach (GameObject muzzle in muzzleFlash) { muzzle.light.enabled = true; muzzle.particleSystem.Play(); muzzleFlashInterval = 0.0f; } // Raycast in bullet direction RaycastHit hit; if (Physics.Raycast(position, direction, out hit, 100.0f, ignoreLayer)) { if (hit.collider.gameObject.tag == "PlayerOne") { HitFlash.FlashCamera(1); if (PlayerOneHealth.DeductHP(Damage)) { returnValue = true; } } else if (hit.collider.gameObject.tag == "PlayerTwo") { HitFlash.FlashCamera(2); if (PlayerTwoHealth.DeductHP(Damage)) { returnValue = true; } } } } return(returnValue); }
public Drone(float movementSpeed, float rotationSpeed, GameObject drone, GameObject[] patrolRoute, EnemySighting enemySighting, float stoppingDistance, float chaseWaitTime, LastPlayerSighting lastPlayerSighting, float shootRate, GameObject[] muzzleFlash, float droneDamage, GameObject droneFireSound, Vector3[] colorSet) : base(movementSpeed, rotationSpeed, drone) { index = 0; chaseTimer = 0.0f; this.drone = drone; this.patrolRoute = patrolRoute; this.movementSpeed = movementSpeed; this.enemySighting = enemySighting; this.stoppingDistance = stoppingDistance; this.chaseWaitTime = chaseWaitTime; this.lastPlayerSighting = lastPlayerSighting; inverseLayer = ~(1 << LayerMask.NameToLayer("Drone") | 1 << LayerMask.NameToLayer("SniperCollider")); inverseShootLayer = ~(1 << LayerMask.NameToLayer("Drone") | 1 << LayerMask.NameToLayer("SmokeBomb") | 1 << LayerMask.NameToLayer("SniperCollider")); Random.seed = System.Environment.TickCount; trackTime = 0.0f; GameObject playerOne = GameObject.FindGameObjectWithTag("PlayerOne"); GameObject playerTwo = GameObject.FindGameObjectWithTag("PlayerTwo"); playerOneMovement = playerOne.GetComponent <FirstPersonMovement>(); if (playerTwo != null) { playerTwoMovement = playerTwo.GetComponent <FirstPersonMovement>(); } droneAnimator = drone.GetComponent <Animator>(); this.muzzleFlash = muzzleFlash; PlayerHealth playerOneHealth = playerOne.GetComponent <PlayerHealth>(); PlayerHealth playerTwoHealth = null; if (playerTwo != null) { playerTwoHealth = playerTwo.GetComponent <PlayerHealth>(); } hitFlash = GameObject.FindGameObjectWithTag("GameManager").GetComponent <HitFlash>(); this.droneWeapon = new DroneWeapon(droneDamage, 1.0f / shootRate, playerOneHealth, playerTwoHealth, droneFireSound, hitFlash, muzzleFlash, droneAnimator); foreach (Transform t in drone.transform) { if (t.tag == "DroneLight") { Vector3 rgb = colorSet[ColorIndex(shootRate, droneDamage)]; Color threatColor = new Color(rgb[0] / 255f, rgb[1] / 255f, rgb[2] / 255f, 1); t.gameObject.light.color = threatColor; break; } } }