void Update() { Timer += Time.deltaTime; if (Timer >= TimeoutSeconds) { EmeraldObjectPool.Despawn(gameObject); } }
void Update() { //Continue to have our AI projectile follow the direction of its target until it colliders with something if (!Collided && HeatSeekingRef == HeatSeeking.No && ProjectileDirection != Vector3.zero || !TargetInView && !Collided && ProjectileDirection != Vector3.zero) { transform.position = transform.position + ProjectileDirection * Time.deltaTime * ProjectileSpeed; transform.rotation = Quaternion.LookRotation(ProjectileDirection); } //Give our fired projectile a 20th of a second to leave the caster's hand before following the target's position. //This is to stop the projectile from firing behind the caster if the target happens to get behind them while they're firing. if (!Collided && HeatSeekingRef == HeatSeeking.Yes && TargetInView) { if (!HeatSeekingFinished) { HeatSeekingInitializeTimer += Time.deltaTime; if (HeatSeekingInitializeTimer < 0.05f) { transform.position = transform.position + ProjectileDirection * Time.deltaTime * ProjectileSpeed; } if (HeatSeekingInitializeTimer >= 0.05f) { transform.Translate(Vector3.Normalize(((ProjectileCurrentTarget.position + AdditionalHeight) - transform.position)) * Time.deltaTime * ProjectileSpeed); HeatSeekingTimer += Time.deltaTime; if (HeatSeekingTimer >= HeatSeekingSeconds) { LastDirection = Vector3.Normalize(((ProjectileCurrentTarget.position + AdditionalHeight) - transform.position)); HeatSeekingFinished = true; } } } else if (HeatSeekingFinished && LastDirection != Vector3.zero) { transform.position = transform.position + LastDirection * Time.deltaTime * ProjectileSpeed; transform.rotation = Quaternion.LookRotation(LastDirection); } } //Track our time since instantiation, once the Timeout time has been reachd, despawn TimeoutTimer += Time.deltaTime; if (TimeoutTimer >= TimeoutTime) { EmeraldObjectPool.Despawn(gameObject); } if (Collided) { CollisionTimer += Time.deltaTime; if (CollisionTimer >= CollisionTime) { EmeraldObjectPool.Despawn(gameObject); } } }
//Handle all of our collision related calculations here. When this happens, effects and sound can be played before the object is despawned. void OnTriggerEnter(Collider C) { if (!Collided && EmeraldSystem != null && ProjectileCurrentTarget != null && C.gameObject == ProjectileCurrentTarget.gameObject) { if (EffectOnCollisionRef == EffectOnCollision.Yes) { if (CollisionEffect != null) { SpawnedEffect = EmeraldObjectPool.Spawn(CollisionEffect, transform.position, Quaternion.identity); SpawnedEffect.transform.SetParent(Emerald_AI.ObjectPool.transform); } } if (ImpactSound != null && SoundOnCollisionRef == EffectOnCollision.Yes) { CollisionSound = EmeraldObjectPool.Spawn(CollisionSoundObject, transform.position, Quaternion.identity); CollisionSound.transform.SetParent(Emerald_AI.ObjectPool.transform); AudioSource CollisionAudioSource = CollisionSound.GetComponent <AudioSource>(); CollisionAudioSource.PlayOneShot(ImpactSound); } if (EmeraldSystem.TargetTypeRef == Emerald_AI.TargetType.AI && EmeraldSystem.TargetEmerald != null) { EmeraldSystem.TargetEmerald.Damage(EmeraldSystem.CurrentDamageAmount, Emerald_AI.TargetType.AI); } else if (EmeraldSystem.TargetTypeRef == Emerald_AI.TargetType.Player) { EmeraldSystem.DamagePlayer(); } else if (EmeraldSystem.TargetTypeRef == Emerald_AI.TargetType.NonAITarget) { //Custom code damaging a non-AI object can be added here, if desired. } Collided = true; ProjectileCollider.enabled = false; } else if (!Collided && EmeraldSystem != null && ProjectileCurrentTarget != null && C.gameObject != ProjectileCurrentTarget.gameObject && C.gameObject != EmeraldSystem.gameObject && C.gameObject.layer != 2) { Collided = true; ProjectileCollider.enabled = false; if (EffectOnCollisionRef == EffectOnCollision.Yes) { if (CollisionEffect != null) { SpawnedEffect = EmeraldObjectPool.Spawn(CollisionEffect, transform.position, Quaternion.identity); SpawnedEffect.transform.SetParent(Emerald_AI.ObjectPool.transform); } } if (ImpactSound != null && SoundOnCollisionRef == EffectOnCollision.Yes) { CollisionSound = EmeraldObjectPool.Spawn(CollisionSoundObject, transform.position, Quaternion.identity); CollisionSound.transform.SetParent(Emerald_AI.ObjectPool.transform); AudioSource CollisionAudioSource = CollisionSound.GetComponent <AudioSource>(); CollisionAudioSource.PlayOneShot(ImpactSound); } } }
void Update() { if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)) { if (CurrentCompanions < TotalAllowedCompanions) { //Spawn our AI using the Emerald Object Pool system GameObject SpawnedAI = EmeraldObjectPool.Spawn(CompanionAIObject, transform.position + transform.forward * 5 + (Random.insideUnitSphere * 2), Quaternion.identity); //Set an event on the created AI to remove the AI on death SpawnedAI.GetComponent <Emerald_AI>().DeathEvent.AddListener(() => { RemoveAI(); }); //Add the spawned AI to the total amount of currently spawn AI CurrentCompanions++; } } }
void Update() { if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)) { //if (CurrentCompanions < TotalAllowedCompanions) //{ //Spawn our AI using the Emerald Object Pool system GameObject DogBitesMan = EmeraldObjectPool.Spawn(objectToSpawn, transform.position, Quaternion.identity); //Set an event on the created AI to remove the AI on death //SpawnedAI.GetComponent<Emerald_AI>().DeathEvent.AddListener(() => { RemoveAI(); }); //Add the spawned AI to the total amount of currently spawn AI // CurrentCompanions++; //} } }
void Update() { if (!calculatedHit) { attackTimer += Time.deltaTime; } attackSoundTimer += Time.deltaTime; if (calculatedHit) { timer += Time.deltaTime; if (hit.collider == null) { //calculatedHit = false; } if (timer >= attackDelay) { if (hit.collider != null && hit.collider.gameObject.GetComponent <Emerald_AI>() != null) { if (HitTags.Contains(hit.collider.gameObject.tag)) { if (useBloodEffect) { GameObject SpawnedEffect = EmeraldObjectPool.Spawn(bloodEffect, hit.point, Quaternion.identity); SpawnedEffect.transform.parent = transform.root; } if (!audioDisabled && useImpactSounds) { _audioSource.PlayOneShot(impactSounds[Random.Range(0, impactSounds.Count)]); } hit.collider.gameObject.GetComponent <Emerald_AI>().Damage(damage, Emerald_AI.TargetType.Player); } } if (hit.collider != null && hit.collider.tag == "Untagged" || hit.collider != null && hit.collider.tag == "Terrain") { if (hitOtherEffect != null && useHitEffect) { GameObject SpawnedEffect = EmeraldObjectPool.Spawn(hitOtherEffect, hit.point, Quaternion.LookRotation(hit.normal)); SpawnedEffect.transform.parent = transform.root; } if (!audioDisabled && useImpactOtherSounds) { _audioSource.PlayOneShot(impactOtherSounds[Random.Range(0, impactOtherSounds.Count)]); } } damage = Random.Range(MinDamage, MaxDamage); attackTimer = 0; calculatedHit = false; timer = 0; } } }