Hey, I am new and I am working on a project for a point of sale software using Unity UI , just to learn to code and I used Buttons for each items in the Menu and they would give out a number when pressed then created a list to collect its price and name. 1. Now I am having problems with finding the total sum of all the items. 2. Getting an error for array out of range.
This is the script where I get the number and calculate the total, I am getting array out of range error in Line 60.
public class OrderInfo : MonoBehaviour
public int iQuandity, oNumber;
public Text meal = new Text;
private double indiPrice;
public bool buttonPressed;
public double grandTotal;
orderins = GameObject.Find("Order Inspector");
menuList = orderins.GetComponent<MenuList>();
itemList = orderins.GetComponent<OrderProcess>();
newText = orderins.GetComponent<CreateText>();
iQuandity = 0;
indiPrice = new double[oNumber];
buttonPressed = false;
public void OrderProcess(int num)
//when the button is pressed it gives out an appropriate number
iNumber = num;
buttonPressed = true;
if (iQuandity == 1)
if (iQuandity > 1)
for (int i = 0; i < oNumber; i++)
**indiPrice[i] = TotalCost();**
public double TotalCost()
total = iQuandity * menuList.iPrice[iNumber];
Please help me out !!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
3 People are following this question.
Multiple Cars not working
Index out of Range Exception Error
Forcing a program to initialize inside Unity game.
Distribute terrain in zones
Help using LitJson