Ejemplo n.º 1
0
    public void Spawn()
    {
        if (!GameplayController.CanUpdate() || cooling || resources.current < 10)
        {
            return;
        }

        //pick a spawner
        int        idx      = Random.Range(0, 3);
        Vector3    spawnPos = spawners [idx].position;
        GameObject newUnit  = Instantiate(unitPref) as GameObject;

        newUnit.transform.SetParent(unitsContainer);
        newUnit.transform.position   = spawnPos;
        newUnit.transform.localScale = Vector3.one;

        //if autopilot on, pick an order
        if (autoPilot)
        {
            int order = resources.current <= 15 ? UnitController.COLLECT : Random.Range(0, 3);
            newUnit.SendMessage("SetOrder", order);
        }

        cooling            = true;
        resources.current -= 10;
    }
Ejemplo n.º 2
0
 void ExtractResource(GameObject tower)
 {
     if (GameplayController.CanUpdate() && health > 0)
     {
         tower.SendMessage("ModifyResources", 2);
     }
 }
Ejemplo n.º 3
0
 void ModifyHealth(float val)
 {
     if (GameplayController.CanUpdate())
     {
         health.current += val;
         health.current  = Mathf.Clamp(health.current, 0, health.max);
     }
 }
Ejemplo n.º 4
0
 void ModifyResources(float val)
 {
     if (GameplayController.CanUpdate())
     {
         resources.current += val;
         resources.current  = Mathf.Clamp(resources.current, 0, resources.max);
     }
 }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (!GameplayController.CanUpdate())
        {
            return;
        }

        resources.current += resourcesSpeed * Time.deltaTime;
        UpdateCooldown();
        AutoSpawn();
    }
Ejemplo n.º 6
0
    void ModifyHealth(float val)
    {
        if (GameplayController.CanUpdate())
        {
            health += val;
            health  = Mathf.Clamp(health, 0, 5);

            if (health <= 0)
            {
                state = UnitState.dead;
            }
        }
    }
Ejemplo n.º 7
0
    void ModifyHealth(float val)
    {
        if (GameplayController.CanUpdate())
        {
            health += val;
            health  = Mathf.Clamp(health, 0, 15);

            if (health <= 0)
            {
                health = 0;
                timer  = 0;
            }
        }
    }
Ejemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        if (!GameplayController.CanUpdate())
        {
            return;
        }

        audioSrc.maxDistance = originalSoundMaxDistance * GameBoard.scale;

        //check for near enemies while target is the main target
        if (target == mainTarget)
        {
            target = CheckForEnemies();
        }

        //enemy killed look for new target

        /*if (target == null && (order == DEFEND || order == ATTACK)) {
         *      state = UnitState.idle;
         *      target = CheckForEnemies ();
         * }*/

        //resource is empty, look for a new one
        if (curResource != null && curResource.health <= 0 && order == COLLECT)
        {
            state  = UnitState.idle;
            target = mainTarget = GetClosestResource();
        }

        //no targets at all, go back to main target and idle
        if (target == null)
        {
            target = mainTarget;
            state  = UnitState.idle;
        }

        switch (state)
        {
        case UnitState.idle: Idle(); break;

        case UnitState.walk: Walk(); break;

        case UnitState.attack: Attack(); break;

        case UnitState.dead: Die(); break;

        default: break;
        }
    }
Ejemplo n.º 9
0
 // Update is called once per frame
 void Update()
 {
     if (health <= 0 && GameplayController.CanUpdate())
     {
         rock.SetActive(false);
         destroyed.SetActive(true);
         timer += Time.deltaTime;
         if (timer >= 15)
         {
             rock.SetActive(true);
             destroyed.SetActive(false);
             timer  = 0;
             health = 15;
         }
     }
 }