Search Unity

Newbie In need

Discussion in 'Editor & General Support' started by SArmour, Jul 30, 2014.

  1. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    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
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Which part are you having trouble with?
     
  3. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    getting the Hello World in the top left corner of the screen. In preview its not there
     
  4. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You will need to attach that script to a GameObject in the scene for it to show anything.
     
  5. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Daniel it tells me to drag the script to the Hierarchy window and drop it on the main camera object which I have done
     
  6. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    What happens when you press the Play button to run your game?
     
  7. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    A Blue Screen and that's it
     
  8. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You're certain it isn't just very small text?

    Try this and let us know what is being reported in the console.
    Code (csharp):
    1. public void OnGUI() {
    2.     GUILayout.Label("Hello World");
    3.     Debug.Log ("This should get logged in the Console");
    4. }
     
  9. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    100% its not I will print screen it and post it
     
  10. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Here is the screen shots with your code Daniel and nothing :(
     

    Attached Files:

  11. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    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.
     
    SArmour likes this.
  12. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Thanks I have now updated it and still nothing :(
     

    Attached Files:

  13. Josh-Naylor

    Josh-Naylor

    Administrator

    Joined:
    Jul 1, 2014
    Posts:
    216
    The script is still not saved so it will not be effective within the editor. File -> Save in Notepad++
     
    SArmour likes this.
  14. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Ok I will try this thanks Josh
     
  15. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
  16. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Hey Guys Back again. This is my good for a Tick Tac Toe game but I have an error message I need help :(

    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.


    Code (CSharp):
    1. public class SquareState : MonoBehaviour {
    2.  
    3. public enum SquareState {
    4.   Clear,
    5.   XControl,
    6.   OControl
    7. }
    8. }
    9.  
     
  17. TRuoss

    TRuoss

    Joined:
    Dec 5, 2012
    Posts:
    85
    the enum <name> is the same as the class <name> this is not allowed in c#


    you can do something like this:

    Code (CSharp):
    1. public class Square : MonoBehaviour
    2. {
    3.    public enum SquareState
    4. {
    5.   ....
    6. }
    7. }
     
  18. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    I change it and it doesn't like it either.

    I have another script

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SquareState : MonoBehaviour {
    5.  
    6. public enum SquareState {
    7.   Clear,
    8.   XControl,
    9.   OControl
    10. }
    11. }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TicTacToeControl : MonoBehaviour {
    5.  
    6. public SquareState[] board = new SquareState[9];
    7. public bool xTurn = true;
    8.  
    9. public void OnGUI() {
    10.    float width = 75;
    11.    float height = 75;
    12.  
    13. for(int y=0;y<3;y++) {
    14.     for(int x=0;x<3;x++) {
    15.  
    16. int boardIndex = (y * 3) + x;
    17.  
    18. Rect square = new Rect (x * width, y * height, width, height);
    19.  
    20. string owner = board[boardIndex] == SquareState.XControl ? "X"  :
    21. board[boardIndex] == SquareState.OControl ? "O" : "";
    22.  
    23. if(GUI.Button(square, Owner))
    24.   SetControl (boardIndex);
    25.             }
    26.         }
    27.     }
    28. public void SetControl(int boardIndex) {
    29.   if(boardIndex < 0 || boardIndex >= board.Length) return;
    30.  
    31.   board[boardIndex] = xTurn ? SquareState.XControl : SquareState.
    32. OControl;
    33.   xTurn = !xTurn;
    34. }
    35. }
    These are my 2 scripts so far.

    Top one Titled SquareState
    Bottom one titled TicTacToeControl
     
  19. TRuoss

    TRuoss

    Joined:
    Dec 5, 2012
    Posts:
    85
    read the error msg: SquareState.SquareState': member names cannot be the same as their enclosing type

    and than look into your SquareState class.
     
    Graham-Dunnett likes this.
  20. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Hi TRuoss I do apologies I am still learning and I changed the details like you said earlier but it made more errors.
     
  21. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    If a change makes more errors, it doesn't necessarily mean that it was the wrong change. Just that the first error was hiding many others.
     
  22. TRuoss

    TRuoss

    Joined:
    Dec 5, 2012
    Posts:
    85
    your following errors come from this, i think:

    Code (CSharp):
    1. string owner = board[boardIndex] == SquareState.XControl ? "X"  :
    2. board[boardIndex] == SquareState.OControl ? "O" : "";
    after changing the first file you have to change this to Square.SquareState.XControl. if you had named the class Square
     
    Last edited: Aug 8, 2014
  23. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Cheers TRuoss I am going to have another pop at this today. decided to rest my brain for a couple of days.
     
  24. SArmour

    SArmour

    Joined:
    Jul 30, 2014
    Posts:
    14
    Yay thanks TRuoss I fixed it.!! :D