void OnTriggerEnter(Collider col) { if (_started || !StaticUtil.LayerMatchTest(CanUseThis, col.gameObject)) { return; } _started = true; int i = 0; if (SpawnPoints.Length == 0) { Debug.LogWarning("Spawn Trigger Warning: No spawn points are specified so this trigger effectively does nothing."); return; } foreach (GameObject point in SpawnPoints) { if (!SpawnerPrefabs[i]) { Debug.LogError("Spawn Trigger Error: You specify a spawn point, but no Spawner Prefab. Can't proceed without a valid Prefab of the Spawner that you to create."); break; } GameObject s = (GameObject)StaticUtil.Spawn(SpawnerPrefabs[i], point.transform.position, point.transform.rotation); Spawner x = s.GetComponent <Spawner>(); _remainingSpawners.Add(x); x.Owner = this; i++; } StartCoroutine(CloseDoors()); StartCoroutine(VictoryLoop()); }
/// <summary> /// Starts the pickup sequence /// </summary> void CreateNewWeapon(GameObject weaponPrefab) { if (weaponPrefab == null) { return; } if (_hand == null) { Debug.LogError("Incorrect Rig Type on " + gameObject.name + "! Must be Humanoid. Check the Import Settings for this model and correct the type. Also confirm the Avatar Configuration has no errors."); return; } GameObject newToy = (GameObject)StaticUtil.Spawn(weaponPrefab, _hand.position, _hand.rotation); Weapon wx = newToy.GetComponent <Weapon>(); wx.Owner = this; WeaponListRuntime.Add(newToy); newToy.transform.SetParent(gameObject.transform); newToy.SetActive(false); if (LogDebug) { Debug.Log("Adding Weapon to Subject " + newToy.name + "..."); } }
void OnEnable() { if (Stats.SpawnFx) { StaticUtil.Spawn(Stats.SpawnFx, transform.position, transform.rotation); } // Pooling... ? }
private IEnumerator FireRanged() { if (Stats.CurrentAmmo >= Stats.AmmoCost) { DoFireEffect(); Vector3 pos = Stats.ProjectileSpawnPoints[_nextSpawnPt].transform.position; Quaternion rot = Stats.ProjectileSpawnPoints[_nextSpawnPt].transform.rotation; if (Stats.Accuracy < 1.0f) { float a = Mathf.Clamp(Stats.Accuracy, 0, 1) - 1; rot.x += Random.Range(-0.2f * a, 0.2f * a); rot.y += Random.Range(-0.2f * a, 0.2f * a); rot.z += Random.Range(-0.2f * a, 0.2f * a); } GameObject thisBullet = StaticUtil.Spawn(Stats.FiresProjectile, pos, rot) as GameObject; if (thisBullet != null) { thisBullet.GetComponent <Projectile>().Owner = Owner; // assign the bullet owner, for points, etc. } if (_ejector != null) { _ejector.Emit(1); // if there is a shell casing ejector, use it. } if (Stats.ProjectileSpawnPoints.Count > 1) // if using multiple spawn points, iterate through them. { _nextSpawnPt++; if (_nextSpawnPt > Stats.ProjectileSpawnPoints.Count - 1) { _nextSpawnPt = 0; } } Stats.CurrentAmmo -= Stats.AmmoCost; Owner.DoWeaponFire(); yield return(StartCoroutine(FireCooldown())); yield break; } if (MagIsEmpty() && Stats.AutoReload) { yield return(StartCoroutine(Reload())); yield break; } // the IFs failed [and did not yield break], so this code is reached and we are indeed out of ammo. yield return(StartCoroutine(NoAmmo())); }
public void SpawnWave() { foreach (KeyValuePair <GameObject, int> key in EnemyReferences) { for (int i = 0; i < key.Value; i++) { Transform t = Positions[Random.Range(0, (Positions.Count))].transform; if (Owner) { Owner.AddToEnemies(StaticUtil.Spawn(key.Key, t.position, t.rotation) as GameObject); } } } }
public void LevelUp() { if (Stats.Level.Actual >= Stats.Level.Max) { return; } if (OnLevelChange != null) { OnLevelChange(); } if (Stats.LevelUpFx) { StaticUtil.Spawn(Stats.LevelUpFx, transform.position, Quaternion.identity); } SetLevelAndStats((int)Stats.Level.Actual + 1); }
private void PopFx(int index) { if (ImpactSounds[index] != null) { AudioSource.PlayClipAtPoint(ImpactSounds[index], _endPoint); } else { Debug.LogWarning(gameObject.name + " cannot spawn Impact sound because it is null. Check the Impact Tag List."); } if (ImpactEffects[index] != null) { StaticUtil.Spawn(ImpactEffects[index], _endPoint, Quaternion.LookRotation(_endNormal)); } else { Debug.LogWarning(gameObject.name + " cannot spawn Impact effect because it is null. Check the Impact Tag List."); } }
private void PopFx(int entry, Vector3 position) { if (ImpactSounds[entry] != null) { AudioSource.PlayClipAtPoint(ImpactSounds[entry], position); } else { Debug.LogWarning(gameObject.name + " cannot spawn Impact sound because it is null. Check the Impact Tag List."); } if (ImpactEffects[entry] != null) { StaticUtil.Spawn(ImpactEffects[entry], position, Quaternion.identity); } else { Debug.LogWarning(gameObject.name + " cannot spawn Impact effect because it is null. Check the Impact Tag List."); } }
private void DoDamageAoe() { // could use foo.SendMessage, but it is sloppy... Rather pay for GetComponent instead. RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, Stats.AoeRadius, Vector2.up, 0.1f, Mask); foreach (RaycastHit2D thisHit in hits) { _victimGo = thisHit.collider.gameObject; _victim = _victimGo.GetComponent <Subject>(); if (Stats.AoeForce > 0) { Rigidbody2D rb = _victimGo.GetComponent <Rigidbody2D>(); Vector3 dir = (rb.transform.position - transform.position); float wearoff = 1 - (dir.magnitude / Stats.AoeRadius); if (rb != null) { rb.AddForce(dir.normalized * Stats.AoeForce * wearoff); } } if (_victim != null) { _victim.DoDamage(Stats.Damage, Owner); Owner.Stats.DamageDealt += Stats.Damage; } // TODO Hit FX // Hit FX per AoE contact not yet working. // // _endPoint = thisHit.point; // SetupImpactNormal(thisHit.normal); // PopFx(GetCorrectFx(thisHit.collider.gameObject)); FinishImpact(); } if (Stats.AoeEffect != null) { StaticUtil.Spawn(Stats.AoeEffect, transform.position, Quaternion.identity); } }
/// <summary> /// Timed period of downage (mostly dead). Could be revived. DeSpawn after timer ends - then totally dead. /// </summary> private IEnumerator CrippleAndDie() { // Drop to a crippled state and wait. if (Stats.CrippledTime > 0) { yield return(new WaitForSeconds(Stats.CrippledTime)); } if (Stats.DeathFx) { StaticUtil.Spawn(Stats.DeathFx, transform.position, transform.rotation); } for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(false); } // Detatch the corpse model and give it an expiration timer. Stats.DeadBodyObj.SetActive(true); Lifetimer c = Stats.DeadBodyObj.AddComponent <Lifetimer>(); c.Lifetime = Stats.CorpseTime; DeSpawn(); }
/// <summary> /// Begins the Subject's death. Subjects can be 'down-but-not-out' for a period of time, then completely die. /// </summary> void Die() { // Deny controls, reset velocity, turn off ai, turn off collider if (_isControllable) { SetInputPermission(false, false, false); } _myRigidbody.velocity = Vector3.zero; _myRigidbody.angularVelocity = 0f; if (GetComponent <Intellect>() != null) { GetComponent <Agent>().enabled = false; } GetComponent <Collider2D>().enabled = false; if (Stats.DeathFx) { StaticUtil.Spawn(Stats.DeathFx, transform.position, Quaternion.identity); } if (OnDeath != null) { OnDeath(); } // Update stats Stats.Deaths++; LastAttacker.Stats.Kills++; StaticUtil.GiveXp((int)Stats.XpReward.Actual, LastAttacker); // IsDead = true; StartCoroutine(CrippleAndDie()); }
private void DoMuzzleFlash() { // TODO should muzzle flash be on the projectile or the weapon? Poll users for suggestions. StaticUtil.Spawn(AttackEffect, transform.position, transform.rotation); }
public void ShowHitIndicator(Vector2 normal) { Quaternion rot = Quaternion.AngleAxis(Mathf.Atan2(normal.y, normal.x) * Mathf.Rad2Deg, Vector3.forward); StaticUtil.Spawn(Stats.HitIndicator, transform.position, rot); }