How can I set a word to be the "discount" word?

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;

	}

}

}

Shouldn’t line 60 be:

discountCode.text == "discount"

Because you want to apply discount if the discountCode.text is the discount word.

Is the applyDiscount() method the onClick event for the button? If so, add a reference to the button in your script:

public Button applyDiscountButton;

If (discountCode.text == “discount”) is true, then inside the if-block add:

applyDiscountButton.interactable = false;

That will prevent the player from clicking the button over and over again after applying the correct discount.

As for the actual text that is currently hard-coded to “discount” you could pull that in from a resource file or a database at run-time and put it in a private member field. Then change line 60 (again!) to:

discountCode.text == discountCodeWord;