Reputation: 58
I have just started learning the language C# from the book "Learning C# by Developing Games with Unity 3d". I have been working through the book fine up until page 47 when it gives me the following code.
using UnityEngine;
using System.Collections;
public class LearnScript : MonoBehaviour
{
public int number1 = 2;
public int number2 = 3;
public int number3 = 4;
void start()
{
AddTwoNumbers(number1, number2);
AddTwoNumbers(number1, number3);
AddTwoNumbers(number2, number3);
}
void update()
{
}
void AddTwoNumbers (int firstNumber, int secondNumber)
{
int result = firstNumber + secondNumber;
Debug.Log(result);
}
}
What the book says it is meant to do is output the answers to the AddTwoNumbers
method, but when I click play on unity the console is empty.
I have attached the code to the main camera so that shouldn't be a problem there. If someone can tell me what I am doing wrong it would be appreciated. I don't want to move on with the book until I get this little bit of code to work. If it makes any difference I am using Unity version 5.2.3.
Upvotes: 3
Views: 1288
Reputation: 843
First, make sure this is attached to some object in the scene.
Second, rename:
void Start()
{
AddTwoNumbers(number1, number2);
AddTwoNumbers(number1, number3);
AddTwoNumbers(number2, number3);
}
Start()
, not start()
.
Also it is Update()
, not update()
.
C# is case sensitive.
Upvotes: 9