private void Shoot() { if (isShooting) { if (Time.time > lastShootTime + shootingCooldown) { lastShootTime = Time.time; GameObject bullet = bulletPool.ActivateObject(); if (bullet == null) { return; } OnShoot?.Invoke(); cameraShake.InduceMotion(0.1f); BulletMovement bulletMovement = bullet.GetComponent <BulletMovement>(); bullet.transform.position = transform.position + new Vector3(bulletOffset.x * Mathf.Cos(transform.rotation.eulerAngles.z * Mathf.Deg2Rad), bulletOffset.y * Mathf.Sin(transform.rotation.eulerAngles.z * Mathf.Deg2Rad)); bulletMovement.angle = transform.rotation.eulerAngles.z; bulletMovement.Move(); AudioManager.Instance.PlaySoundAtPosition(shootSFX, bullet.transform.position); } } }
/// <summary> /// Spawns an alien at a random angle along the radius of the circle /// </summary> private void Spawn() { GameObject objectToSpawn = m_pooler.ActivateObject(); objectToSpawn.transform.position = transform.position; objectToSpawn.transform.rotation = Quaternion.Euler(new Vector3(0, 0, Random.Range(0f, 359f))); objectToSpawn.transform.Translate(new Vector3(0f, m_circleRadius, 0f), Space.Self); }
public void GenerateAsteroidSlices(MeshData leftData, MeshData rightData, Vector2 leftCentroid, Vector2 rightCentroid, Vector3 preVelocity, Vector3 slicerVelocity) { Asteroid leftAsteroid, rightAsteroid; Vector3 preVelLeft = Quaternion.Euler(0, 0, 90) * slicerVelocity * splitForce; Vector3 preVelRight = Quaternion.Euler(0, 0, -90) * slicerVelocity * splitForce; bool spawnedLeft = false, spawnedRight = false; if (leftData.GetArea() > areaThreshold) { leftAsteroid = asteroidPool.ActivateObject().GetComponent <Asteroid>(); leftAsteroid.parentGenerator = this; leftAsteroid.SetMesh(leftData); leftAsteroid.transform.position = leftCentroid; leftAsteroid.transform.rotation = Quaternion.identity; leftAsteroid.Move((preVelocity + slicerVelocity + preVelLeft) * momentumFactor, AsteroidGenerationRNG.Instance.NextFloat(-1, 1) * splitRotation); spawnedLeft = true; } if (rightData.GetArea() > areaThreshold) { rightAsteroid = asteroidPool.ActivateObject().GetComponent <Asteroid>(); rightAsteroid.parentGenerator = this; rightAsteroid.SetMesh(rightData); rightAsteroid.transform.position = rightCentroid; rightAsteroid.transform.rotation = Quaternion.identity; rightAsteroid.Move((preVelocity + slicerVelocity + preVelRight) * momentumFactor, AsteroidGenerationRNG.Instance.NextFloat(-1, 1) * splitRotation); spawnedRight = true; } if (spawnedLeft && spawnedRight) { AudioManager.Instance.PlaySoundAtPosition(splitSFX, transform.position); } else if (spawnedLeft || spawnedRight) { AudioManager.Instance.PlaySoundAtPosition(filteredSplitSFX, transform.position); } else { AudioManager.Instance.PlaySoundAtPosition(destructionSFX, transform.position); } }
/// <summary> /// Shoots a bullet that is created from the object pooler /// </summary> public void Shoot(float a_timerAmount = 0f) { GameObject bulletToFire = m_bulletPooler.ActivateObject(a_timerAmount); if (bulletToFire == null) return; bulletToFire.SetActive(false); bulletToFire.transform.position = transform.position; bulletToFire.transform.rotation = transform.rotation; bulletToFire.transform.Translate(m_locationSpawnOffset, Space.Self); bulletToFire.SetActive(true); }
public GameObject ActivateObject(string key, Vector3 position) { return(Pooler.ActivateObject(key, position)); }