private void ShootGun(Vector3 direction) { //Shoot if has more ammo than 0 in mag if (currentAmmoInMag > 0) { if (timeSinceLastShot >= fireRate) { timeSinceLastShot = 0f; currentAmmoInMag -= 1; //New shoot PooledObject bullet = bulletPool.GetObject(); bullet.transform.position = this.transform.position; bullet.GetComponent <Rigidbody2D>().velocity = direction * bulletSpeed; bullet.GetComponent <Bullet>().shooter = this.gameObject; bullet.GetComponent <Bullet>().damage = damage; /* * //Old shoot * //shoot * RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, gunRange, enemyLayer); * * Debug.DrawRay(transform.position, direction * gunRange, Color.yellow, 5f); * * // Does the ray intersect any objects excluding the player layer * if (hit) * { * hit.collider.gameObject.GetComponent<Character>().TakeDamage(damage); * }*/ } } }
public void Initialize() { filter = gameObject.GetComponent <MeshFilter>(); filter.mesh.Clear(); transparentChunk.GetComponent <MeshFilter>().mesh.Clear(); col = gameObject.GetComponent <MeshCollider>(); _glassrenderer = transparentChunk.GetComponent <MeshRenderer>(); _renderer = gameObject.GetComponent <MeshRenderer>(); _blocks = new ushort[Size * Size * Size]; _changes = new List <uint>(); update = false; updating = false; built = false; rendered = false; surrounded = false; outofrange = false; if (column != null) { column.spawned = false; column.rendered = false; column.chunks.Clear(); } for (int i = 0; i < _blocks.Length; i++) { _blocks[i] = Block.Null; } StartSlowUpdate(); }
private void SpawnEnemies() { for (int i = 0; i < amountOfEnemiesToSpawn * currentWave; i++) { //select a random number for chosing what to spawn int randomEnemyType = Random.Range(0, 2); //select a random spawnpoint to spawn enemy Transform randomSpawnPos = enemySpawnPoints[Random.Range(0, enemySpawnPoints.Length - 1)]; //Based on the previous numbers spawn an enemy switch (randomEnemyType) { case 0: PooledObject enemy = zombiePool.GetObject(); allEnemies.Add(enemy); enemy.gameObject.transform.position = randomSpawnPos.position; Zombie enemyScript = enemy.GetComponent <Zombie>(); enemyScript.health = enemyScript.defaultHealth; break; case 1: PooledObject rangedEnemy = rangedZombiePool.GetObject(); allEnemies.Add(rangedEnemy); rangedEnemy.gameObject.transform.position = randomSpawnPos.position; RangedZombie rangedEnemyScript = rangedEnemy.GetComponent <RangedZombie>(); rangedEnemyScript.bulletPool = bulletPool; rangedEnemyScript.health = rangedEnemyScript.defaultHealth; break; } } }
protected override void DoFire() { PooledObject pooledObject = ObjectPoolManager.Instance.GetPooledObject(Data.WeaponData.GetAmmoPool(WeaponType), FighterManager.Instance.AmmoContainer.transform); Bullet bullet = pooledObject?.GetComponent <Bullet>(); bullet?.Initialize(Fighter, SlotId, WeaponType, Damage); }
public static T Create <T>(T prefab, Transform parent = null) where T : Component { T newInstance = null; //component of the prefab to check wether it should be pooled PooledObject pooledPrefab = prefab.GetComponent <PooledObject>(); //check if it is a pooled object if (pooledPrefab != null) { Pool pool = GetObjectPool(pooledPrefab); PooledObject pooledInstance = pool.GetInstance(parent); return(pooledInstance.GetComponent <T>()); } else { newInstance = Instantiate(prefab, parent); } return(newInstance); }
void SetSpawnedPooledObject(PooledObject entity) { if (entity) { AnimatedProjectile pulledEntity = entity.GetComponent <AnimatedProjectile>(); pulledEntity.transform.position = transform.position; pulledEntity.transform.rotation = transform.rotation; pulledEntity.Reset(transform); if (alternatingFire) { pulledEntity.Alternate(currentAltFireState); if (currentAltFireState) { currentAltFireState = false; } else { currentAltFireState = true; } } } else { Debug.Log("no projectile??"); } }
public void SpawnEnemy(PooledObject prefab, PathNodes enemyPath) { if (!m_pooledLevelObjects.ContainsKey(prefab)) { m_pooledLevelObjects[prefab] = new SimplePool(20, prefab); } PooledObject spawnEnemy = m_pooledLevelObjects[prefab].GetFromPool(); spawnEnemy.GetComponent <Enemy>().MovementPath = enemyPath; }
private IEnumerator Spawner(Fighter target) { for (int i = 0; i < SpecialData.SpawnAmount; ++i) { PooledObject pooledObject = ObjectPoolManager.Instance.GetPooledObject(Data.SpecialData.GetAmmoPool(SpecialType), FighterManager.Instance.AmmoContainer.transform); Missile missile = pooledObject?.GetComponent <Missile>(); missile?.Initialize(Fighter, target, SpecialData.Type, SpecialData.Damage); yield return(new WaitForSeconds(SpecialData.SpawnRateSeconds)); } }
public T GetPooled <T>(GameObject Blueprint) { PooledObject pooled = GetPooled(Blueprint); if (!pooled) { return(default(T)); } return(pooled.GetComponent <T>()); }
private void ShootGun(Vector3 direction) { //Shoot if has more ammo than 0 in mag if (currentAmmoInMag > 0) { if (timeSinceLastShot >= fireRate) { timeSinceLastShot = 0f; currentAmmoInMag -= 1; //New shoot PooledObject bullet = bulletPool.GetObject(); bullet.transform.position = this.transform.position; bullet.GetComponent <Rigidbody2D>().velocity = direction * bulletSpeed; bullet.GetComponent <Bullet>().shooter = this.gameObject; bullet.GetComponent <Bullet>().damage = damage; } } }
/// <summary> /// Creates an AudioClipPlayer and plays it in a given world space. /// </summary> /// <param name="toPlay">The audio clip to be played.</param> /// <param name="position">The position in world space to play the audio from.</param> /// <param name="minVolume">The minimum volume of the clip. (To be combined with the audio managers volume modifier)</param> /// <param name="maxVolume">The maximum volume of the clip. (To be combined with the audio managers volume modifier)</param> /// <param name="minPitch">The minimum pitch of the clip.</param> /// <param name="maxPitch">The maximum pitch of the clip.</param> /// <param name="minPan">The minimum left to right pan of the clip.</param> /// <param name="maxPan">The maximum left to right pan of the clip.</param> public void PlayClipWorldSpace(AudioClip toPlay, Vector3 position, float minVolume = 1f, float maxVolume = 1f, float minPitch = 1f, float maxPitch = 1f, float minPan = 0f, float maxPan = 0f) { if (toPlay == null) { Debug.LogError("AudioManager cannot play a null clip in the world space position " + position.ToString()); return; } PooledObject obj = ObjectPoolingManager.instance.CreateObject(audioClipPlayer); obj.transform.position = position; AudioClipPlayer clipPlayer = obj.GetComponent <AudioClipPlayer>(); clipPlayer.PlaySoundRandom(toPlay, minVolume, maxVolume, minPitch, maxPitch, minPan, maxPan); }
public void SpawnImpact(SpecialData.SpecialType specialType, Vector3 position) { PooledObject pooledObject = ObjectPoolManager.Instance.GetPooledObject(SpecialData.GetImpactPool(specialType), AmmoContainer.transform); Impact impact = pooledObject?.GetComponent <Impact>(); if (null == impact) { return; } impact.transform.position = position; StartCoroutine(ImpactCoroutine(pooledObject)); }
/// <summary> /// Creates an AudioClipPlayer and plays it in local space. /// </summary> /// <param name="toPlay">The audio clip to be played.</param> /// <param name="minVolume">The minimum volume of the clip. (To be combined with the audio managers volume modifier)</param> /// <param name="maxVolume">The maximum volume of the clip. (To be combined with the audio managers volume modifier)</param> /// <param name="minPitch">The minimum pitch of the clip.</param> /// <param name="maxPitch">The maximum pitch of the clip.</param> /// <param name="minPan">The minimum left to right pan of the clip.</param> /// <param name="maxPan">The maximum left to right pan of the clip.</param> public void PlayClipLocalSpace(AudioClip toPlay, float minVolume = 1f, float maxVolume = 1f, float minPitch = 1f, float maxPitch = 1f, float minPan = 0f, float maxPan = 0f) { if (toPlay == null) { Debug.LogError("AudioManager cannot play a null clip in local space."); return; } PooledObject obj = ObjectPoolingManager.instance.CreateObject(audioClipPlayer, Camera.main.transform, -1); obj.transform.Reset(); AudioClipPlayer clipPlayer = obj.GetComponent <AudioClipPlayer>(); clipPlayer.PlaySoundRandom(toPlay, minVolume, maxVolume, minPitch, maxPitch, minPan, maxPan); }
IEnumerator ExplodeRoutine(Column column) { Color spawnColor; Vector3 pos; Spawns spawn; isLive = false; if (type == PickupType.Black) { spawn = Spawns.BlackPickup; } else { spawn = Spawns.SilverPickup; } float size = Mathf.Ceil(transform.localScale.x); for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { for (int z = 0; z < size; z++) { pos = new Vector3( transform.position.x - (transform.localScale.x * 0.5f) + ((1 / (size * 2)) * transform.localScale.x) + ((x / size) * transform.localScale.x), transform.position.y - (transform.localScale.y * 0.5f) + ((1 / (size * 2)) * transform.localScale.y) + ((x / size) * transform.localScale.x), transform.position.z - (transform.localScale.z * 0.5f) + ((1 / (size * 2)) * transform.localScale.z) + ((x / size) * transform.localScale.x) ); //spawnColor = Tile.Colors[(x + y + z) % 64]; spawnColor = Color.Lerp(color, Tile.Inverse(Tile.Brighten(color, 0.5f)), (x * y * z) / (size * size * size)); PooledObject obj = World.Spawn.Object(spawn, spawnColor, mass, pos, 0f); if (obj != null) { column.spawns.Add(obj); Pickup pickup = obj.GetComponent <Pickup>(); pickup.Activate(0.4f); //SpawnManager.Pickups.Add(pickup); } _renderer.enabled = !_renderer.enabled; yield return(new WaitForSeconds(Config.SpawnTiming)); } } } _renderer.enabled = true; transform.localScale = new Vector3(1f, 1f, 1f); ReturnToPool(); }
private void SpawnPlayer() { if (player) { player.ReturnToPool(); } //select a random spawnpoint to spawn player Transform randomSpawnPos = playerSpawnPoints[Random.Range(0, playerSpawnPoints.Length - 1)]; player = playerPool.GetObject(); Player playerScript = player.GetComponent <Player>(); playerScript.bulletPool = bulletPool; playerScript.health = playerScript.defaultHealth; player.transform.position = randomSpawnPos.position; }
void OnValidate() { // Check shell prefab is valid if (m_ProjectilePrefab != null && m_ProjectilePrefab.GetComponent <IProjectile>() == null) { Debug.Log("Projectile prefab must have IProjectile component attached (such as a BallisticProjectile): " + m_ProjectilePrefab.name); m_ProjectilePrefab = null; } if (m_MuzzleSpeed < 1f) { m_MuzzleSpeed = 1f; } if (m_Gravity < 0f) { m_Gravity = 0f; } }
void Detonate() { if (timer < Time.time && detonated == false) { Vector3 spawnPosition = this.gameObject.transform.position; for (int i = 0; i < projectilesToSpawn; i++) { PooledObject spawnedProjectile = prefabToSpawn.GetPooledInstance <PooledObject>(); spawnedProjectile.transform.position = spawnPosition; spawnedProjectile.transform.localRotation = Quaternion.Euler(0, 0, angle * i); spawnedProjectile.GetComponent <BaseProjectile>().ResetProjectileVariables(spawnedProjectile.transform); } detonated = true; if (repeat) { SetTimer(secondsUntilDetonation); } } }
private Chain CreateChain() { if (Globals.ChainPrefab != null) { PooledObject chainObject = Globals.ChainObjectPool.GetObject(); if (chainObject != null) { return(chainObject.GetComponent <Chain>()); } else { return(Instantiate(Globals.ChainPrefab)); } } else { Debug.LogError("No valid Chain Prefab"); return(null); } }
// Update is called once per frame void Update() { if (!inBetweenWaves) { //Spawn enemies timeSinceLastSpawn += Time.deltaTime; timeSinceLastWave += Time.deltaTime; if (timeSinceLastSpawn > timeBetweenEnemySpawns) { timeSinceLastSpawn = 0; SpawnEnemies(); } //if certain amount of time has passed if (timeSinceLastWave >= waveLength) { EndWave(); currentWave++; } } if (inBetweenWaves) { //if enter is pressed, start wave if (Input.GetKeyDown(KeyCode.Return)) { StartWave(); } } //If player is dead, game over if (!player.GetComponent <Character>().alive) { uiManager.GameOver(); } }
private GridBox GenerateGridBox(Coordinate c) { if (Globals.GridBoxPrefab == null) { Debug.LogError("No valid GridBox Prefab"); return(null); } GridBox gridBox; PooledObject gridBoxObject = Globals.GridBoxObjectPool.GetObject(); if (gridBoxObject != null) { gridBox = gridBoxObject.GetComponent <GridBox>(); } else { gridBox = Instantiate(Globals.GridBoxPrefab); } gridBox.Initialize(c, GetSpawnLocation(c)); gridBox.transform.parent = this.transform; return(gridBox); }
SpawnedObject SpawnPickup(PooledObject prefab, Color color, int key, float corruption) { Pickup pickup = prefab.GetPooledInstance <Pickup>(); if (pickup == null && SleptPickups.Count > 0) { Pickup sleeper = SleptPickups[0]; Pickups.Remove(sleeper); SleptPickups.RemoveAt(0); if (sleeper != null) { sleeper.ReturnToPool(); pickup = prefab.GetPooledInstance <Pickup>(); } } if (pickup == null) { return(null); } pickup.type = ((Pickup)prefab).type; pickup.isLive = true; pickup.inRange = true; Pickups.Add(pickup); if (pickup.type == PickupType.Basic) { pickup.color = Color.Lerp(Tile.Brighten(color, 0.7f), Color.white, 0.1f); pickup.size = 0.5f; pickup.rotationSpeed = 2f; pickup.baseScore = 10; pickup.driftIntensity = 2000f; pickup.hasAction = true; pickup.hsvColor = new ColorHSV(color); int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, pickup.hsvColor.h)); //int scoreNote = Mathf.FloorToInt(Mathf.Lerp(0f, 23.999f, pickup.hsvColor.h)); var playSound = pickup.GetComponent <PlayHitSound>(); playSound.worldHitSound = pickupOctave[(int)(scales[key][note])]; playSound.objectHitSound = pickupOctave[(int)(scales[key][note])]; int scale = Mathf.FloorToInt(Mathf.Lerp(0f, 4.999f, pickup.hsvColor.h)); playSound.scoreSound = score2Octave[key * 3 + scale]; } if (pickup.type == PickupType.Silver) { pickup.color = Color.Lerp(Tile.Brighten(color, 0.3f), Color.white, 0.5f); pickup.size = 1f; pickup.baseScore = 50; pickup.driftIntensity = 20000f; pickup.hasAction = true; pickup.rotationSpeed = 8f; pickup.hsvColor = new ColorHSV(color); int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, pickup.hsvColor.h)); var playSound = pickup.GetComponent <PlayHitSound>(); playSound.worldHitSound = pickupOctave[(int)scales[key][note]]; playSound.objectHitSound = bigPickupOctave[(int)scales[key][note]]; int scale = Mathf.FloorToInt(Mathf.Lerp(0f, 4.999f, pickup.hsvColor.h)); playSound.scoreSound = scoreOctave[key * 5 + scale]; } if (pickup.type == PickupType.Black) { pickup.color = Color.Lerp(Tile.Brighten(color, 0.3f), Color.black, 0.35f); pickup.size = 1f; pickup.baseScore = 25; pickup.driftIntensity = 10000f; pickup.hasAction = true; pickup.rotationSpeed = 4f; pickup.hsvColor = new ColorHSV(color); int note = Mathf.FloorToInt(Mathf.Lerp(0f, 6.999f, pickup.hsvColor.h)); var playSound = pickup.GetComponent <PlayHitSound>(); playSound.worldHitSound = pickupOctave[(int)scales[key][note]]; playSound.objectHitSound = darkPickupOctave[(int)scales[key][note]]; int scale = Mathf.FloorToInt(Mathf.Lerp(0f, 4.999f, pickup.hsvColor.h)); playSound.scoreSound = scoreOctave[key * 5 + scale]; } return((SpawnedObject)pickup); }
void Split(float velocity) { Column column = World.GetColumn(World.GetChunkPosition(transform.position)); if (column != null) { Spawns spawn; //Color spawnColor = hsvColor.ToColor(); Vector3 scale = transform.localScale * 0.5f; float newSpawnValue = SpawnValue * 0.25f; int splits = 1; if (velocity > 20f) { splits = 2; } else if (velocity > 30f) { splits = 3; } else if (velocity > 50f) { splits = 4; } else if (velocity > 80f) { splits = 5; } if (type == BallType.Imploding) { spawn = Spawns.MysteryEgg; } else if (type == BallType.Exploding) { spawn = Spawns.SuperBouncyBall; } else if (type == BallType.Moon) { spawn = Spawns.Moon; } else if (type == BallType.DarkStar) { spawn = Spawns.DarkStar; } else { spawn = Spawns.BouncyBall; scale = transform.localScale; newSpawnValue = 1f; splits *= 3; } List <ProceduralToolkit.ColorHSV> newColors = hsvColor.GetAnalogousPalette(splits); int count = 0; StartCoroutine(RepeatThen(splits, 0.1f, () => { PooledObject obj = World.Spawn.Object(spawn, newColors[count].ToColor(), mass, transform.position, Mathf.Lerp(0f, corruption, Random.value)); count++; if (obj != null) { obj.transform.localScale = scale; BouncyBall ball = obj.GetComponent <BouncyBall>(); // Prevent moon explosions if (ball.type == BallType.Moon) { ball.growthRate = 1.05f; } ball.Activate(0.5f); ball.SpawnValue = newSpawnValue; column.spawns.Add(obj); } }, () => { Explode(); })); } }
// Instantiate projectile through Object pool void ShootPrefab(PooledObject prefab) { PooledObject spawnedProjectile = prefab.GetPooledInstance <PooledObject>(); spawnedProjectile.GetComponent <BaseProjectile>().ResetProjectileVariables(muzzle); }