Exemplo n.º 1
0
    /// <summary>
    /// Spawns a projectile in the field.
    ///
    /// If absoluteWorldCoord is set to false, location specifies a relative position in the field. 0.0 = left/bottom, 1.0 = right/top. Values greater than 1 or less than 0 spawn
    /// outside of of the camera view.
    /// </summary>
    /// <param name="prefab">Prefab for the spawned projectile, describes the visuals, size, and hitbox characteristics of the prefab.</param>
    /// <param name="location">The location within the field to spawn the projectile.</param>
    /// <param name="rotation">Rotation.</param>
    /// <param name="absoluteWorldCoord">If set to <c>true</c>, <c>location</c> is in absolute world coordinates relative to the bottom right corner of the game plane.</param>
    /// <param name="extraControllers">Extra ProjectileControllers to change the behavior of the projectile.</param>
    public Projectile SpawnProjectile(ProjectilePrefab prefab, Vector2 location, float rotation, CoordinateSystem coordSys = CoordinateSystem.Screen, ProjectileController[] extraControllers = null)
    {
        Vector3 worldLocation = Vector3.zero;

        switch (coordSys)
        {
        case CoordinateSystem.Screen:
            worldLocation = WorldPoint(new Vector3(location.x, location.y, gamePlaneDistance));
            break;

        case CoordinateSystem.FieldRelative:
            worldLocation = BottomLeft + new Vector3(location.x, location.y, 0f);
            break;

        case CoordinateSystem.AbsoluteWorld:
            worldLocation = location;
            break;
        }
        Projectile projectile = (Projectile)bulletPool.Get(prefab);

        projectile.Transform.position = worldLocation;
        projectile.Transform.rotation = Quaternion.Euler(0f, 0f, rotation);
        projectile.Active             = true;
        return(projectile);
    }
Exemplo n.º 2
0
 public void Explode()
 {
     for (int i = 0; i < Size; i++)
     {
         GameObject projectile = ProjectilePool.Get();
         projectile.SetActive(true);
         projectile.transform.position = transform.position + new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f));
         Rigidbody rb = projectile.GetComponent <Rigidbody>();
         rb.AddForce(Impulse * new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f)), ForceMode.Impulse);
     }
 }
Exemplo n.º 3
0
    private void Shoot()
    {
        var projectile = projectilePool.Get();

        projectile.transform.position = muzzles[lastMuzzleIndex].position;
        projectile.transform.forward  = transform.forward;

        lastShotTimestamp = Time.time;
        lastMuzzleIndex   = (lastMuzzleIndex < muzzles.Count - 1)
            ? lastMuzzleIndex + 1
            : 0;
    }
Exemplo n.º 4
0
    public void Emit()
    {
        // Reset the initial state of the gameobject
        GameObject projectile = ProjectilePool.Get();         // Ask the pool for the object

        projectile.SetActive(true);
        projectile.transform.position = transform.position + new Vector3(0, 1, 0);
        // Reset the initial state of the physics (rigidbody)
        Rigidbody rb = projectile.GetComponent <Rigidbody>();

        rb.AddForce(gameObject.transform.forward * Impulse + new Vector3(Random.Range(0f, 1f),
                                                                         Random.Range(0f, 1f), Random.Range(0f, 1f)), ForceMode.Impulse);
    }
Exemplo n.º 5
0
        private void SpawnProjectiles()
        {
            int activeTurrets = (int)_stats.GetStatValue(StatType.ProjectilesCount);

            for (int i = 0; i < activeTurrets; i++)
            {
                Projectile projectile = _projectilePool.Get();

                if (projectile)
                {
                    projectile.Initialize(_stats.ProjectileModifiers, _stats,
                                          _turrets[i].transform, _avoidTarget);

                    projectile.gameObject.SetActive(true);
                }
            }
        }