private void OnTriggerEnter(Collider other) { if (!other.isTrigger) { if (audioSource != null && ImpactSound != null && !audioSource.isPlaying) { audioSource.clip = ImpactSound; audioSource.Play(); } DamageAbleObject damageObject = other.gameObject.GetComponent <DamageAbleObject>(); if (damageObject != null) { Detonate(damageObject); } else { if (DestroyOnCollisionWithWall) { if (other.CompareTag("Untagged")) { Destroy(gameObject); } } if (!startDetonationTimer) { startDetonationTimer = true; } } } }
// Use this for initialization private void Start() { currentCollider = GetComponent <Collider>(); ability = GetComponentInParent <Ability>(); damageAbleObject = GetComponentInChildren <DamageAbleObject>(); damageAbleObject.OnDeath += DamageAbleObject_OnDeath; }
private void Detonate(DamageAbleObject collisionObject) { if (collisionObject != null) { bool isTeam = attacker != null && collisionObject.transform.CompareTag(Attacker.tag); DoDamage(collisionObject.gameObject, collisionObject, damage, isTeam); } if (SpawnExplosion) { if (Explosion != null) { GameObject explosionObj = Instantiate(Explosion, transform.position, transform.rotation); Explosion explosionScript = explosionObj.GetComponent <Explosion>(); if (explosionScript != null && OverwriteExplosionValues) { explosionScript.Init(damage, damageRange > 0 ? damageRange : explosionScript.Radius, attacker, 1.2f, DoAOETeamDamage ? TeamDamageMultiplicator : 0); } } } if (DestroyOnCollision) { Destroy(gameObject); } }
private void DoDamage(GameObject victim, DamageAbleObject damageAbleObject, float damage, bool teamDamage) { HitEventArgs hitArgs = new HitEventArgs(damage * (DoTeamDamage ? TeamDamageMultiplicator : 1), attacker, victim, teamDamage, false); if (OnHit != null) { OnHit(this, hitArgs); } if (!hitArgs.Cancel && hitArgs.FinalDamage > 0) { damageAbleObject.DoDamage(attacker, hitArgs.FinalDamage, StatusEffect); } }
private void SpawnPlayers(bool useTeamHealth = true) { if (Player.TeamHealth > 0 || !useTeamHealth) { float shareHealth = Player.TeamHealth / GlobalReferences.PlayerStates.Count; for (int i = 0; i < GlobalReferences.PlayerStates.Count; i++) { if (choice != null) { if (choice[(int)GlobalReferences.PlayerStates[i].Index] == 0) { PlayerPrefab = PlayerPrefabAegis; } else if (choice[(int)GlobalReferences.PlayerStates[i].Index] == 1) { PlayerPrefab = PlayerPrefabStalker; } } else { PlayerPrefab = PlayerPrefabAegis; } GameObject gobj = SpawnPlayer(GlobalReferences.PlayerStates[i], Player.LastCheckpointPosition + new Vector3(i * 2, 3, 0)); if (gobj != null && useTeamHealth) { DamageAbleObject healthContainer = gobj.GetComponent <DamageAbleObject>(); if (healthContainer != null) { if (Player.TeamHealth > GlobalReferences.PlayerStates.Count * healthContainer.MaxHealth) { healthContainer.Health = healthContainer.MaxHealth; Player.TeamHealth -= healthContainer.MaxHealth; } else { healthContainer.Health = shareHealth; Player.TeamHealth -= shareHealth; } } } } } else { Player.LastCheckpointPosition = Vector3.zero; Defeat = true; } }
private void GetDamageScript() { if (characterGameObject != null) { damageScript = characterGameObject.GetComponent <DamageAbleObject>(); if (damageScript == null) { Deactivate(); } } else { Deactivate(); } }
// Use this for initialization private void Start() { game = GameObject.Find("Game"); GameInspector gameInspector = game.GetComponent <GameInspector>(); maxTeamHealth = gameInspector.MaxTeamHealth; GameObject playerPrefab = GameObject.Find("Player"); DamageAbleObject playerDamageable = gameInspector.PlayerPrefab.GetComponent <DamageAbleObject>(); //maxPlayerHealth = playerDamageable.MaxHealth; boss = GameObject.Find("Boss"); bossDamageable = boss.GetComponent <DamageAbleObject>(); maxBossHealth = bossDamageable.MaxHealth; bossHealthFill = BossHealthbar.GetComponent <Image>(); Time.timeScale = 1; GlobalReferences.CurrentGameState = GlobalReferences.GameState.Play; }
// Use this for initialization private void Start() { anim = transform.FindChild("Crawler_Animation").GetComponent <Animator>(); dmgobjct = GetComponent <DamageAbleObject>(); if (dmgobjct != null) { dmgobjct.OnDeath += Dmgobjct_OnDeath; dmgobjct.OnNewStatusEffect += Dmgobjct_OnNewStatusEffect; } if (PrimaryWeapon != null) { primaryWeapon = Instantiate(PrimaryWeapon, transform).GetComponent <Weapon>(); } moveScript = GetComponent <MoveScript>(); if (moveScript != null) { moveScript.AddGravity = false; } navAgent = GetComponent <NavMeshAgent>(); if (navAgent != null) { navAgent.stoppingDistance = attackRange; } GameObject[] enemyList = GameObject.FindGameObjectsWithTag("Enemy"); for (int i = 0; i < enemyList.Length; i++) { Enemy enemy = enemyList[i].GetComponent <Enemy>(); if (enemy != null) { if (enemy.squadID == squadID) { squadList.Add(enemy); } } } SetUI(); }
private void OnTriggerEnter(Collider other) { bool isTeam = false; if (owner != null) { isTeam = other.transform.CompareTag(owner.tag); } DamageAbleObject healthContainer = other.gameObject.GetComponent <DamageAbleObject>(); if (healthContainer != null) { float distance = Vector3.Distance(other.transform.position, transform.position); float rangeDamage = damage; if (UseDamageReduction) { rangeDamage = (damageReduction - (distance / radius)) * damage; if (rangeDamage <= 0) { return; } } if (isTeam) { rangeDamage *= teamDamageMultiplicator; } HitEventArgs hitArgs = new HitEventArgs(rangeDamage, owner, other.gameObject, isTeam, true); if (OnHit != null) { OnHit(this, hitArgs); } if (!hitArgs.Cancel && hitArgs.FinalDamage > 0) { healthContainer.DoDamage(owner, rangeDamage, StatusEffect); } exploded = true; } }
private void UpdateHealth(Player playerScript, DamageAbleObject damageAbleObject, GameObject player) { switch (playerScript.Index) { case PlayerIndex.One: { player1HealthBar_2.fillAmount = damageAbleObject.Health / damageAbleObject.MaxHealth; player1Heat.fillAmount = playerScript.GetHeat(1) / playerScript.GetMaxHeat(1); if (P1UseAmmo) { P1Reloading = playerScript.GetAmmo(); if (P1Reloading == true) { player1Heat2.fillAmount = 1; } else { player1Heat2.fillAmount = 0; } } else { player1Heat2.fillAmount = playerScript.GetHeat(2) / playerScript.GetMaxHeat(2); } AbilityFill[2].fillAmount = playerScript.GetHeat(3) / playerScript.GetMaxHeat(3); AbilityFill[6].fillAmount = (playerScript.MaxEnergy(1) - playerScript.AbilityEnergy(1)) / playerScript.MaxEnergy(1); AbilityFill[10].fillAmount = (playerScript.MaxEnergy(2) - playerScript.AbilityEnergy(2)) / playerScript.MaxEnergy(2); AbilityFill[14].fillAmount = (playerScript.MaxEnergy(3) - playerScript.AbilityEnergy(3)) / playerScript.MaxEnergy(3); if (Indicate == null) { Indicate = Instantiate(P1IndicatorPlane); } if (P1iconsSet == false) { SetIcon(player, PlayerIndex.One); SetWeaponIcon(player, PlayerIndex.One); SetAbilityIcons(player, PlayerIndex.One); P1iconsSet = true; } Indicate.transform.SetParent(playerScript.transform, false); } break; case PlayerIndex.Two: { player2HealthBar_2.fillAmount = damageAbleObject.Health / damageAbleObject.MaxHealth; player2Heat.fillAmount = playerScript.GetHeat(1) / playerScript.GetMaxHeat(1); //player2Heat2.fillAmount = playerScript.GetHeat(2) / playerScript.GetMaxHeat(2); if (P2UseAmmo) { P2Reloading = playerScript.GetAmmo(); if (P2Reloading == true) { player2Heat2.fillAmount = 1; } else { player2Heat2.fillAmount = 0; } } else { player2Heat2.fillAmount = playerScript.GetHeat(2) / playerScript.GetMaxHeat(2); } AbilityFill[18].fillAmount = playerScript.GetHeat(3) / playerScript.GetMaxHeat(3); AbilityFill[22].fillAmount = (playerScript.MaxEnergy(1) - playerScript.AbilityEnergy(1)) / playerScript.MaxEnergy(1); AbilityFill[26].fillAmount = (playerScript.MaxEnergy(2) - playerScript.AbilityEnergy(2)) / playerScript.MaxEnergy(2); AbilityFill[30].fillAmount = (playerScript.MaxEnergy(3) - playerScript.AbilityEnergy(3)) / playerScript.MaxEnergy(3); if (Indicate2 == null) { Indicate2 = Instantiate(P2IndicatorPlane); } if (P2iconsSet == false) { SetIcon(player, PlayerIndex.Two); SetWeaponIcon(player, PlayerIndex.Two); SetAbilityIcons(player, PlayerIndex.Two); P2iconsSet = true; } Indicate2.transform.SetParent(playerScript.transform, false); } break; case PlayerIndex.Three: { player3HealthBar_2.fillAmount = damageAbleObject.Health / damageAbleObject.MaxHealth; player3Heat.fillAmount = playerScript.GetHeat(1) / playerScript.GetMaxHeat(1); //player3Heat2.fillAmount = playerScript.GetHeat(2) / playerScript.GetMaxHeat(2); if (P3UseAmmo) { P3Reloading = playerScript.GetAmmo(); if (P3Reloading == true) { player3Heat2.fillAmount = 1; } else { player3Heat2.fillAmount = 0; } } else { player3Heat2.fillAmount = playerScript.GetHeat(2) / playerScript.GetMaxHeat(2); } AbilityFill[34].fillAmount = playerScript.GetHeat(3) / playerScript.GetMaxHeat(3); AbilityFill[38].fillAmount = (playerScript.MaxEnergy(1) - playerScript.AbilityEnergy(1)) / playerScript.MaxEnergy(1); AbilityFill[42].fillAmount = (playerScript.MaxEnergy(2) - playerScript.AbilityEnergy(2)) / playerScript.MaxEnergy(2); AbilityFill[46].fillAmount = (playerScript.MaxEnergy(3) - playerScript.AbilityEnergy(3)) / playerScript.MaxEnergy(3); if (Indicate3 == null) { Indicate3 = Instantiate(P3IndicatorPlane); } if (P3iconsSet == false) { SetIcon(player, PlayerIndex.Three); SetWeaponIcon(player, PlayerIndex.Three); SetAbilityIcons(player, PlayerIndex.Three); P3iconsSet = true; } Indicate3.transform.SetParent(playerScript.transform, false); } break; case PlayerIndex.Four: { player4HealthBar_2.fillAmount = damageAbleObject.Health / damageAbleObject.MaxHealth; player4Heat.fillAmount = playerScript.GetHeat(1) / playerScript.GetMaxHeat(1); //player4Heat2.fillAmount = playerScript.GetHeat(2) / playerScript.GetMaxHeat(2); if (P4UseAmmo) { P4Reloading = playerScript.GetAmmo(); if (P4Reloading == true) { player4Heat2.fillAmount = 1; } else { player4Heat2.fillAmount = 0; } } else { player4Heat2.fillAmount = playerScript.GetHeat(2) / playerScript.GetMaxHeat(2); } AbilityFill[50].fillAmount = playerScript.GetHeat(3) / playerScript.GetMaxHeat(3); AbilityFill[54].fillAmount = (playerScript.MaxEnergy(1) - playerScript.AbilityEnergy(1)) / playerScript.MaxEnergy(1); AbilityFill[58].fillAmount = (playerScript.MaxEnergy(2) - playerScript.AbilityEnergy(2)) / playerScript.MaxEnergy(2); AbilityFill[62].fillAmount = (playerScript.MaxEnergy(3) - playerScript.AbilityEnergy(3)) / playerScript.MaxEnergy(3); if (Indicate4 == null) { Indicate4 = Instantiate(P4IndicatorPlane); } if (P4iconsSet == false) { SetIcon(player, PlayerIndex.Four); SetWeaponIcon(player, PlayerIndex.Four); SetAbilityIcons(player, PlayerIndex.Four); P4iconsSet = true; } Indicate4.transform.SetParent(playerScript.transform, false); } break; default: break; } }
// Use this for initialization private void Start() { dmgobjct = GetComponent <DamageAbleObject>(); dmgobjct.OnDeath += Dmgobjct_OnDeath; }
private void Start() { //create as many audiosources as we want = needed for playing as many sounds simultaniously as we want, same as in player //for example walk and hit sound, or walk and some type of attack for (var tmp = 0; tmp < BossAudioClips.Length; tmp++) { gameObject.AddComponent <AudioSource>(); } BossAudioSources = GetComponents <AudioSource>(); for (var tmp = 0; tmp < BossAudioClips.Length; tmp++) { BossAudioSources[tmp].clip = BossAudioClips[tmp]; } // mainGameObject = GameObject.FindGameObjectWithTag("GameObject"); uiScript = mainGameObject.GetComponent <UIScript>(); damageDone = new float[4]; if (AOEWeapon != null) { GameObject gobj = Instantiate(AOEWeapon, transform); if (gobj != null) { aoeWeapon = gobj.GetComponent <Weapon>(); aoeWeapon.OnPrimaryAttack += OnPrimaryAttack; aoeWeapon.OnDelayedPrimaryAttack += OnPrimaryAttack; } } if (IceWaveWeapon != null) { GameObject gobj = Instantiate(IceWaveWeapon, transform); if (gobj != null) { iceWaveWeapon = gobj.GetComponent <Weapon>(); iceWaveWeapon.OnPrimaryAttack += OnPrimaryAttack; iceWaveWeapon.OnDelayedPrimaryAttack += OnPrimaryAttack; } } if (IcicleAbility != null) { GameObject gobj = Instantiate(IcicleAbility, transform); if (gobj != null) { icicleAbility = gobj.GetComponent <Ability>(); icicleAbility.OnActivated += IcicleAbility_OnActivated; } } healthContainer = GetComponent <DamageAbleObject>(); if (healthContainer != null) { healthContainer.OnDeath += HealthContainer_OnDeath; healthContainer.OnReceiveDamage += HealthContainer_OnReceiveDamage; } moveScript = GetComponent <MoveScript>(); agent = GetComponent <NavMeshAgent>(); playerScripts = new List <Player>(); spawnPosition = transform.position; GetPlayers(); GamePadManager.OnPlayerCountChanged += GamePadManager_OnPlayerCountChanged; }
// Use this for initialization private void Start() { Renderer[] renderers = GetComponentsInChildren <Renderer>(); for (int i = 0; i < renderers.Length; i++) { for (int m = 0; m < renderers[i].materials.Length; m++) { if (renderers[i].materials[m].mainTexture == changeAbleMaterial.mainTexture) { Material[] materials = renderers[i].materials; materials[m] = playerMaterials[(int)index]; GetComponentsInChildren <Renderer>()[i].materials = materials; } } } foreach (Transform item in transform) { if (item.CompareTag("ProjectileSpawn")) { if (item.name == "Left") { leftSpawn = item.gameObject; } else if (item.name == "Right") { rightSpawn = item.gameObject; } } } //create as many audiosources as we want = needed for playing as many sounds simultaniously as we want for (var tmp = 0; tmp < AudioClips.Length; tmp++) { gameObject.AddComponent <AudioSource>(); } audioSources = GetComponents <AudioSource>(); Array.Resize(ref SoundVolumes, AudioClips.Length); for (var tmp = 0; tmp < AudioClips.Length; tmp++) { audioSources[tmp].clip = AudioClips[tmp]; audioSources[tmp].volume = SoundVolumes[tmp]; } deniedSource = gameObject.AddComponent <AudioSource>(); //define names for sounds var Spawn_Sound = audioSources[0]; //var Despawn_Sound = audioSources[1]; //var Walk_Ice_1_Sound = audioSources[3]; 3-7 Ice_Walk //var Walk_Ice_2_Sound = audioSources[4]; 8-12 Metal_Walk //var Walk_Ice_3_Sound = audioSources[5]; 13-17 Oil_Walk //var Walk_Ice_4_Sound = audioSources[6]; 18-22 Snow_Walk //var Walk_Ice_5_Sound = audioSources[7]; //var Hit1_Sound = audioSources[7]; 23-26 Hit //for(int i = 3; i < 17; i++) //{ // audioSources[i].volume = StepVolume; //} //TODO call sounds in correct places/functions //play sound by its name defined above Spawn_Sound.Play(); mainCamera = Camera.main; mainCamera.GetComponentInParent <FollowingCamera>().AddToCamera(transform); mainGameObject = GameObject.FindGameObjectWithTag("GameObject"); uiScript = mainGameObject.GetComponent <UIScript>(); if (DashAbility != null) { GameObject dash = Instantiate(DashAbility, gameObject.transform); if (dash != null) { dashAbility = dash.GetComponent <Ability>(); dashAbility.OnActivated += DashAbility_OnActivated; dashAbility.OnAbort += DashAbility_OnAbort; dashAbility.OnUsing += DashAbility_OnUsing; } } physics = GetComponent <Rigidbody>(); if (PrimaryWeapon != null) { primaryWeapon = Instantiate(PrimaryWeapon, transform).GetComponent <Weapon>(); primaryWeapon.OnPrimaryAttack += PrimaryWeapon_OnPrimaryAttack; primaryWeapon.OnSecondaryAttack += PrimaryWeapon_OnSecondaryAttack; primaryWeapon.OnDelayedPrimaryAttack += PrimaryWeapon_OnDelayedPrimaryAttack; primaryWeapon.OnDelayedSecondaryAttack += PrimaryWeapon_OnDelayedSecondaryAttack; primaryWeapon.OnSpawning += PrimaryWeapon_OnSpawning; } if (SecondaryWeapon != null) { secondaryWeapon = Instantiate(SecondaryWeapon, transform).GetComponent <Weapon>(); secondaryWeapon.OnPrimaryAttack += SecondaryWeapon_OnPrimaryAttack; secondaryWeapon.OnSecondaryAttack += SecondaryWeapon_OnSecondaryAttack; secondaryWeapon.OnDelayedPrimaryAttack += SecondaryWeapon_OnDelayedPrimaryAttack; secondaryWeapon.OnDelayedSecondaryAttack += SecondaryWeapon_OnDelayedSecondaryAttack; secondaryWeapon.OnSpawning += SecondaryWeapon_OnSpawning; } if (GrenadeWeapon != null) { grenadeWeapon = Instantiate(GrenadeWeapon, transform).GetComponent <Weapon>(); grenadeWeapon.OnPrimaryAttack += GrenadeWeapon_OnPrimaryAttack; } if (Ability != null) { ability = Instantiate(Ability, transform).GetComponent <Ability>(); if (ability.name.Contains("Dash")) { ability.OnActivated += DashAbility_OnActivated; ability.OnAbort += DashAbility_OnAbort; ability.OnUsing += DashAbility_OnUsing; } } if (SecondaryAbility != null) { secondaryAbility = Instantiate(SecondaryAbility, transform).GetComponent <Ability>(); if (secondaryAbility.name.Contains("Dash")) { secondaryAbility.OnActivated += DashAbility_OnActivated; secondaryAbility.OnAbort += DashAbility_OnAbort; secondaryAbility.OnUsing += DashAbility_OnUsing; } } healthContainer = GetComponent <DamageAbleObject>(); if (healthContainer != null) { healthContainer.OnDeath += HealthContainer_OnDeath; healthContainer.OnReceiveDamage += HealthContainer_OnReceiveDamage; healthContainer.OnReceiveHealth += HealthContainer_OnReceiveHealth; } moveScript = GetComponent <MoveScript>(); if (moveScript != null) { moveScript.OnMoving += MoveScript_OnMoving; } MeshFilter meshFilter = GetComponent <MeshFilter>(); if (meshFilter != null) { Mesh mesh = meshFilter.mesh; if (mesh != null) { meshBounds = mesh.bounds.size; } } //Set Immortality Time Value elapsedImmortal = maxImmortality; if (dashTrail != null) { dashParticles = dashTrail.GetComponentsInChildren <ParticleSystem>(); SetDashParticles(false); } }