- Home /
Help with Shop Script C#
So, I'm working on a shop script that pauses the game and opens up a GUI with purchasable items. that part is working, but when I actually buy something, nothing happens. It's kinda coding in a "dirty way" but I don't know anything more elegant. Anyway, here it is:
using UnityEngine;
using System.Collections;
public class SlotScript : MonoBehaviour
{
/// <Items Types>
/// 1: Health Kit
/// 2: Extra Life
/// 3: Player Shield
/// 4: Clones
/// </Item Types>
public bool itemActive = false;
public static bool purchasable = true;
public float MoraleCost = 2;
public float itemType = 1;
public GameObject sprite;
void Awake()
{
}
void OnClick()
{
if(purchasable == true && Morale.secMorale >= MoraleCost)
{
Morale.secMorale = Morale.secMorale - MoraleCost;
Debug.Log("Ello' chaps!");
itemActive = true;
gameObject.SetActiveRecursively(false);
}
}
void OnHover()
{
if(itemType == 1)
{
}
}
void Update()
{
if (itemActive)
{
purchasable = false;
Debug.Log("effects are taking place!");
if(itemType == 1)
{
Player_Health.playerHealth += 100;
}
if(itemType == 2)
{
Player_Health.playerLives = Player_Health.playerLives + 1;
}
if(itemType == 3)
{
Player_Shield.shieldBought = true;
}
if(itemType == 4)
{
Morale.secPopulation = Morale.secPopulation + 10;
}
}
if(purchasable == false)
{
}
}
}
I'm using NGUI btw.
Comment