Beispiel #1
0
    public IBullet Create(Vector2 spawnLocation, Vector2 direction)
    {
        Vector2 initialSpeed = direction * GameManager.GM.BlastBulletSpeed;

        if (_bullets.Count < GameManager.GM.MaxPerPoolBullets)
        {
            IBullet obj = GameObject.Instantiate <IBullet>(BlasterBulletPrefab, transform) as IBullet;
            obj.Create(_owner);
            _bullets.Add(obj);
            obj.Init(initialSpeed);
        }
        _bullets[_latestUsedBullet].OnDestruction();

        _bullets[_latestUsedBullet].transform.position = spawnLocation;
        _bullets[_latestUsedBullet].Init(initialSpeed);

        int lastBullet = _latestUsedBullet;

        _latestUsedBullet = (_latestUsedBullet + 1) % GameManager.GM.MaxPerPoolBullets;

        return(_bullets[lastBullet]);
    }