Stuck on my script

Discussion in 'Game Development (Technical)' started by Beebeebabie, Mar 10, 2014.

  1. Beebeebabie

    Beebeebabie New Member

    Joined:
    Feb 22, 2014
    Messages:
    4
    Likes Received:
    0
    Hi everyone,
    I followed a tutorial on creating a basic Item Database. I'm sure everything is working fine and I get the concept of creating new classes and whatnot
    Im using Unity 3-d and I followed the script 100%. But when I hit play none of the add buttons show up or anything. My list on my interface works and I can add elements but the acutally gameplay scene doesn't show up.

    (This is the script I used)

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;

    public class ItemManager:MonoBehaviour {

    public List<Item> inventory = new List<Item>();

    private string newItemName = "";
    private string newItemCost = "";
    private string newItemDescription = "";

    void ONGUI()
    {

    newItemName = GUILayout.TextField (newItemName);

    newItemCost = GUILayout.TextField (newItemCost);

    newItemDescription = GUILayout.TextField (newItemDescription);

    if (GUILayout.Button("Add New Item"));
    {
    Item newItem = ScriptableObject.CreateInstance<Item>();

    newItem.name = newItemName;
    newItem.cost = System.Convert.ToInt32(newItemCost);
    newItem.description = newItemDescription;



    inventory.Add(newItem);
    }

    for(int i = 0; i <inventory.Count; i ++)
    {
    GUILayout.Label(inventory.name + " - " + inventory.description + " - " + inventory.cost);
    }
    }
    }

    I have my Item script

    using UnityEngine;
    using System.Collections;

    [System.Serializable]
    public class Item : ScriptableObject {

    public int cost = 0;
    public string name ="";
    public string description = "";

    }

    as well. I'm not sure of Im missing something or just the bigger picture.

    As in how well I know Unity, I understand the concepts of attaching scripts to objects in order to add it to the scene, and other basic things but not to much after that. still reading and learning but hoped someone could point me to the right direction! Thanks
     
  2. jefferytitan

    Original Member

    Joined:
    Apr 22, 2006
    Messages:
    361
    Likes Received:
    0
    I'm wondering if it's case sensitivity. In the documentation it's "OnGUI". You have all capitals. Unfortunately because it's just done through method naming rather than an interface or something, there's no compile error to let you know if you spell one wrong.
     
  3. TimS

    Original Member

    Joined:
    Feb 9, 2005
    Messages:
    684
    Likes Received:
    0
    You've got a semicolon at the end of your if(button)...

    "if (GUILayout.Button("Add New Item"));"

    So everything in there will run every frame without the button being pressed... Other than that, I dunno!
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer