Newbie In need

Hello, I am sorry if I have posted in the wrong page but I need some advice. Just to give you a little information about me. My name is Stuart I’m 26 I love technology and everything about it. I have decided I wanted to self learn about game development. So I thought an easy place to start was Android gaming apps. I found a book called ‘Unity Android Game Development by Example (beginner’s guide)’ written by Thomas Finnegan. I don’t know if anyone is familiar with this book.

I have hit a stumble. I have followed the book word for word. I just don’t seem to have any luck getting the finished app. The Task is to create the app ‘Hello World’. The book tells me to Create a C# Script from the menu in the project window. once I have named it HelloWorld Hit enter twice to open the Script up. Then action 17. say’s "For now we will delete the start and update functions that Unity insists on including in every new script. Replace them with a bit of code that simply renders the words Hello World in the top-left corner of the screen. You can now close the script and return to unity.

public void OnGUI() {
GUILayout.Label(“Hello World”);
}

I hope this helps and I am sorry for being a newbie. I just want to learn.

Thank

Stuart

Which part are you having trouble with?

getting the Hello World in the top left corner of the screen. In preview its not there

You will need to attach that script to a GameObject in the scene for it to show anything.

Daniel it tells me to drag the script to the Hierarchy window and drop it on the main camera object which I have done

What happens when you press the Play button to run your game?

A Blue Screen and that’s it

You’re certain it isn’t just very small text?

Try this and let us know what is being reported in the console.

public void OnGUI() {
    GUILayout.Label("Hello World");
    Debug.Log ("This should get logged in the Console");
}

100% its not I will print screen it and post it

Here is the screen shots with your code Daniel and nothing :frowning:

1717422–108280–Screens.rar (901 KB)

On The screenshots in your rar file you did not finish the script and did not save it.
You are missing the closing bracket of the class in the end.

1 Like

Thanks I have now updated it and still nothing :frowning:


The script is still not saved so it will not be effective within the editor. File → Save in Notepad++

1 Like

Ok I will try this thanks Josh

Thanks Josh!!! In the book it doesn’t ask to save the Notepad++ you have solved my Problem and thank you to fffMalzbier, DanielQuick, Graham Dunnett for all your help!!

Hey Guys Back again. This is my good for a Tick Tac Toe game but I have an error message I need help :frowning:

error message: Assets/SquareState.cs(6,13): error CS0542: `SquareState.SquareState’: member names cannot be the same as their enclosing type

Please help PS thanks so much for helping.

public class SquareState : MonoBehaviour {

public enum SquareState {
  Clear,
  XControl,
  OControl
}
}

the enum is the same as the class this is not allowed in c#

you can do something like this:

public class Square : MonoBehaviour
{
   public enum SquareState
{
  ....
}
}

I change it and it doesn’t like it either.

I have another script

using UnityEngine;
using System.Collections;

public class SquareState : MonoBehaviour {

public enum SquareState {
  Clear,
  XControl,
  OControl
}
}
using UnityEngine;
using System.Collections;

public class TicTacToeControl : MonoBehaviour {

public SquareState[] board = new SquareState[9];
public bool xTurn = true;

public void OnGUI() {
   float width = 75;
   float height = 75;
  
for(int y=0;y<3;y++) {
    for(int x=0;x<3;x++) {

int boardIndex = (y * 3) + x;

Rect square = new Rect (x * width, y * height, width, height);

string owner = board[boardIndex] == SquareState.XControl ? "X"  :
board[boardIndex] == SquareState.OControl ? "O" : "";

if(GUI.Button(square, Owner))
  SetControl (boardIndex);
            } 
        }
    }
public void SetControl(int boardIndex) {
  if(boardIndex < 0 || boardIndex >= board.Length) return;

  board[boardIndex] = xTurn ? SquareState.XControl : SquareState.
OControl;
  xTurn = !xTurn;
}
}

These are my 2 scripts so far.

Top one Titled SquareState
Bottom one titled TicTacToeControl

read the error msg: SquareState.SquareState’: member names cannot be the same as their enclosing type

and than look into your SquareState class.

1 Like

Hi TRuoss I do apologies I am still learning and I changed the details like you said earlier but it made more errors.