3

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.

6
  • well... weird. looks right except for the case letters. try Start() and Update(), and make sure it is attached on some object in the scene! Commented Dec 2, 2015 at 20:36
  • Yeah there is no start() method being called in the code.. Commented Dec 2, 2015 at 20:36
  • C# uses cap letter on front of methods. start is not Start. Commented Dec 2, 2015 at 20:38
  • In this case, it would be start() as the code snippet does not show Start().. Commented Dec 2, 2015 at 20:39
  • @ゴスエンヘンリ Thanks a lot for the help. I never realised the names had to be in caps Commented Dec 2, 2015 at 20:42

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.