I am creating a “Shopping Cart” styled game and I would like to add a specific word that would enable the user to get a 10% discount. How can I set a certain word to enable the user to input & receive a discount?
I also would like the Discount button to be disabled after it is used once. How can I disable the button?
My code for the cart is as follows:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEditor;
public class CartManager : MonoBehaviour {
public InputField firstNameinput, lastNameinput;
private string firstName,lastName;
public Text welcomeMessage;
public Text totalAmountTextField, overallAmountTextField;
public float totalAmount, overallAmount; //total is subtotal without tax, overall is with tax
public InputField discountCode;
public int discountPercentage;
public GameObject contentPanel;
// Use this for initialization
void Start () {
createItem ("yoga mat","thick rubber mat",75, "yogamat");
createItem ("pants","orange leggings",25, "IMG_3081");
createItem ("shirt","pink",15, "resize");
createItem ("hat","fitted hat",10, "namaste");
createItem ("shoes","training shoe",60, "shoes");
createItem ("bracelet","one size",3, "IMG_2731 copy");
}
public void createItem(string itemName, string itemDesc, int itemCost, string itemImage) {
Debug.Log ("Creating an Item");
GameObject go = Instantiate (Resources.Load ("Item Panel") as GameObject);
go.transform.SetParent (contentPanel.transform, false);
item item = go.GetComponent<item> ();
item.itemName.text = itemName;
item.itemDesc.text = itemDesc;
item.itemCost.text = "$" + itemCost;
item.realCost = itemCost;
Sprite itemImage_temp = Resources.Load<Sprite> (itemImage);
item.itemImage.sprite = itemImage_temp;
}
// Update is called once per frame
void Update () {
}
public void updateFirstName() {
firstName = firstNameinput.text;
Debug.Log (firstNameinput);
updateDisplayText ();
}
public void updateLastName() {
lastName = lastNameinput.text;
Debug.Log (lastNameinput);
updateDisplayText ();
}
void updateDisplayText () {
welcomeMessage.text = "Welcome " + firstName + " "+ lastName;
}
public void applyDiscount () {
if (discountCode.text != "discount") {
totalAmount = totalAmount * (100 - discountPercentage) / 100;
Debug.Log (totalAmount);
totalAmountTextField.text = "$" + totalAmount;
}
}
}