Here’s the code from the book I’m learning from:
using UnityEngine;
using System.Collections;
public class MemoryTick : MonoBehaviour
{
public int number1 = 2;
public int number2 = 3;
public int number3 = 7;
// Use this for initialization
void Start ()
{
int answer =
AddTwoNumbers (number1, number2) +
AddTwoNumbers (number1, number3) +
AddTwoNumbers (number2, number3);
DisplayResult (answer);
}
int AddTwoNumbers (int firstNumber, int secondNumber)
{
int result = firstNumber + secondNumber;
return result;
}
void DisplayResult(int total)
{
Debug.Log ("The grand total is: " + total);
}
}
I understand most of it, but I do have some questions:
The code shows the two numbers added to eachother, however in the last line of my start method I am calling the method DisplayResult(), why does it need the argument “answer” within it?
I tried without it, and the code won’t execute, has it to do with the “int total”?
if so, in what order is the code being read by unity?
Hope someone can explain it in detail to a total noob thanks