Coding Help

Hi all,

I am creating a scene where there are many pre-defined positions using empty’s, and at these positions I am spawning numbers e.g. 24, 17, 5, 8, 9 to be used to equal to a sum. The player must click the numbers and add it to equal a given sum the player can choose as many numbers to equal the sum.

I know how to spawn stuff in predefined positions.

So how do I:

  1. randomize numbers from 1-100 make it appear on screen
  2. How do i add up which number the player has chosen by clicking e.g. sum is 42: he clicked on 24, 10 and 8 = 42#

I use and am learning in C#

For #1:


For #2:

int sum = 0;
foreach(number in numbersPlayerClickedOn) { sum += number; }
if(sum == 42) { Debug.Log("Player clicked on numbers that sum to 42"); }