Learning C# by Developing Games with Unity 5.x - Second Edition by Greg Lukosek

Learning C# by Developing Games with Unity 5.x - Second Edition by Greg Lukosek

Author:Greg Lukosek [Lukosek, Greg]
Language: eng
Format: azw3, pdf
Publisher: Packt Publishing
Published: 2016-03-31T04:00:00+00:00


We know exactly how to write a class as an object. The next step would be creating an instance of the object of that class. In C#, we use the keyword new to instantiate the object.

The syntax looks like this:

new ObjectType();

So, we are using the keyword new followed by an ObjectType, and then we have the opening and closing brackets. ObjectType is nothing but your class name (we discussed this before).

Each time you instantiate an object of any class, Unity will create some space in the memory to store that object. The issue in the preceding syntax is that we are not assigning that freshly created object anywhere. Therefore, we won't be able to access its data.

The best way is to assign this object to some variable:

ObjectType myObjectInstance = new ObjectType();



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.