Hi guys,
I’m following a Tower Defense tutorial and I am trying to code colour changes in the panels so if a player has enough money to purchase the turret the panel is green, and if they don’t it’s red! I’ve managed to get it work except using one script to manage all the panels but it makes the highest cost apply to all of them. So if I purchase 1 turret (panel, £100) both panels will go red, even though I’ve still got £200 (enough for two standard turrets) – I don’t really want to have to create a script for each panel because it will clog up my folders. Anyway of managing this in one script without getting the problem I have?
(All the stupid names like panel, panel2, are just place holders to be updated later on.)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UICost : MonoBehaviour {
private BuildManager buildManager;
private object panelColor;
private object panelColor2;
private Renderer rend;
Image panel;
Image panel2;
public bool standardTurretHasMoney { get { return PlayerStats.Money >= 100f; } }
public bool Panel2HasMoney { get { return PlayerStats.Money >= 250f; } }
// Use this for initialization
void Start () {
panel = GetComponent<Image>();
panel2 = GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
if (standardTurretHasMoney)
{
panel.color = UnityEngine.Color.green;
}
else
{
panel.color = UnityEngine.Color.red;
}
if (Panel2HasMoney)
{
panel2.color = UnityEngine.Color.green;
}
else
{
panel2.color = UnityEngine.Color.red;
}
}
}
internal class panel
{
internal Color color;
}