Game Development Reference
In-Depth Information
5. Next, we will create a new class named Item , which basically contains the in-
formation of the item, icon, and name. For this, go to Assets | Create | Javascript
(for Unity JavaScript users) or Assets | Create | C# (for C# users), name it Item ,
double-click on it to launch MonoDevelop, and replace the code as follows.
// Unity JavaScript user:
#pragma strict
var icon : Texture;
var info : String;
private var _guiContent : GUIContent;
function get guiContent () : GUIContent {
return new GUIContent(this.name, this.icon,
this.info);
}
// C# user:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Item : MonoBehaviour {
public Texture icon;
public string info;
GUIContent _guiContent;
public GUIContent guiContent {
get { return new GUIContent(this.name, this.icon,
this.info); }
}
}
This class is basically to set the information of each item and then return the in-
formation as GUIContent via the guiContent() function, which will be
shown in our information window.
6. Then, we need to create a class called ItemsContainer to contain all the
items, initializations, and to set the scroll view (which we will use in the next
step); go to Assets | Create | Javascript (for Unity JavaScript users) or Assets |
Search WWH ::




Custom Search