private void OnMouseDown()
    {
        // Set previous seleted button to origin color
        var buttons = FindObjectsOfType <DefenderButton>();

        foreach (DefenderButton defenderButton in buttons)
        {
            defenderButton.GetComponent <SpriteRenderer>().color = oriColor;
        }

        // Set selected button to white
        GetComponent <SpriteRenderer>().color = Color.white;
        FindObjectOfType <DefenderSpawner>().SetSelectedDefender(defenderPrefab);
        // Show star cost of the selected defender
        FindObjectOfType <DisplayStar>().DisplayStarCost(defenderPrefab.GetDefenderStarCost());
    }
Beispiel #2
0
    // Check all requirements before spawn
    private void AttempToSpawnDefender(Vector2 gridPos)
    {
        if (!defenderToSpawn)
        {
            return;
        }
        var displayStar  = FindObjectOfType <DisplayStar>();
        int defenderCost = defenderToSpawn.GetDefenderStarCost();

        if (displayStar.EnoughToSpawn(defenderCost))
        {
            SpawnDefender(gridPos);
            displayStar.SpendStar(defenderCost);
        }
        else
        {
            Debug.Log("Not have enough star to spawn");
        }
    }