Пример #1
0
    void Start()
    {
        mStats.InitMoveStats();

        if (anim == null)
        {
            anim = GetComponentInChildren <Animator>();
        }

        posX             = (int)transform.position.x;
        posY             = (int)transform.position.y;
        enemyAttkHandler = GetComponentInChildren <Enemy_AttackHandler> ();

        if (!isKamikaze)
        {
            GetFirstPath(false);
        }
        else
        {
            GetFirstPath(true);
        }



        _capitalPosition = new Vector2(resourceGrid.capitalSpawnX, resourceGrid.capitalSpawnY);
    }
Пример #2
0
    void SpawnEnemy(string _enemyName, int _spawnIndex)
    {
        // Spawn and fill components
        GameObject _enemy = objPool.GetObjectForType(_enemyName, true);

        if (_enemy != null)
        {
            // Give it its starting position
            _enemy.transform.position = spawnPositions[_spawnIndex];

            // reset its Stats in case it just got brought back from the Pool
            Enemy_AttackHandler _attkHandler = _enemy.GetComponentInChildren <Enemy_AttackHandler>();
            _attkHandler.stats.Init();

            // also reset their Health Bar
            _attkHandler.statusIndicator.SetHealth(_attkHandler.stats.curHP, _attkHandler.stats.maxHP);
            Debug.Log("WAVESPAWNER: spawning unit with curHP: " + _attkHandler.stats.curHP + " and maxHP: " + _attkHandler.stats.maxHP);

            // and give it the Object Pool
            _attkHandler.objPool = objPool;

            // store its position for its neighbors
            neighborEnemyPosition = _enemy.transform.position;

            // pathfinding variables
            Enemy_MoveHandler _moveHandler = _enemy.GetComponent <Enemy_MoveHandler>();
            _moveHandler.resourceGrid  = resourceGrid;
            _moveHandler.spwnPtIndex   = _spawnIndex;
            _moveHandler.spwnPtHandler = spwnPtHandler;

            // reset the current move speed in case this unit was affected by a DeBuffer
            _moveHandler.mStats.curMoveSpeed = _moveHandler.mStats.startMoveSpeed;

            // feed it the move handler from the enemy spawned before this one so it has a buddy
            if (lastEnemy != null)
            {
                // make sure they belong to the same wave
                if (lastEnemy.gameObject.name == _enemyName)
                {
                    _moveHandler.myBuddy = lastEnemy;
                }
                else
                {
                    // not the same name so this must be the first spawn of a new wave
                    lastEnemy = null;
                }
            }

            lastEnemy = _moveHandler;

            // Add this newly Spawned enemy to the list of spawned enemies
            spawnedEnemies.Add(_moveHandler);
        }
    }
Пример #3
0
 void Awake()
 {
     rb = GetComponent<Rigidbody2D>();
     enemy_AttackHandler = GetComponent<Enemy_AttackHandler>();
 }
Пример #4
0
    void Start()
    {
        // Initialize Movement Speed stat
        mStats.InitMoveStats ();

        // Get the Animator
        if (anim == null) {
            anim = GetComponentInChildren<Animator>();
        }

        // Store initial position for Grid as an int
        posX = (int)transform.position.x;
        posY = (int)transform.position.y;

        // Store the Attack Handler to interact with its state
        enemyAttkHandler = GetComponent<Enemy_AttackHandler> ();

        // Get First Path, pass in True argument only if this is a Kamikaze unit
        if (!isKamikaze) {

            GetFirstPath (false);

        } else {

            GetFirstPath(true);
        }

        // Store the Capital position from the resource grid
        if (resourceGrid != null)
            _capitalPosition = new Vector2 (resourceGrid.capitalSpawnX, resourceGrid.capitalSpawnY);

        // This unit has been initialized (meaning it's already been spawned once)
        // In order to know which units already spawned from pool and need to reset stats
        unitInitialized = true;
    }