Game Development Reference
In-Depth Information
}
4. A variable of the
CustomObject
type is added to this class to store the cur-
rent type from the set discussed in the previous step. We use the
public
keyword so that a user can directly set the value of this variable inside the
Unity Editor on an instance of the object:
public CustomObjectTypeobjectType
CustomObjectType objectType;
5. A public variable of the
string
type is added so that Unity users can add
some descriptive text to the object while designing them, as shown in the fol-
lowing code; this can be very helpful while debugging or trying to identify the
objects inside the editor:
public string displayName;
6. Declare a method named
validate()
, which will be used to assign the
unnamed_object
string to the
displayName
field if one has not been as-
signed in the editor, as shown in the following code:
public void validate()
{
if (displayName == "")
displayName = "unnamed_object";
}
Congratulations! We now have a container for the
CustomGameObject
information
that our inventory system will use. To continue, let's create the
InteractiveObj
script.
Implementing the InteractiveObj script
The
InteractiveObj
script declares a class that enables simple animation and
permits player interactions. Perform the following steps to create the script: