-1

I want to "Instantiate" a custom type to the scene. I made it inherit from GameObject by doing so:

Block.prototype = new GameObject();

So,

-will this work, will it inherit from GameObject?

-And how can I "Instantiate" it?

Any help is appreciated, thanks.

Ege F
  • 107
  • 1
  • 1
  • 9

2 Answers2

1

You shouldn't inherit GameObject.

You need to inherit MonoBehaviour.

After you inherit from MonoBehaviour you attach a Component to a GameObject, you can create this from the Unity menu GameObject->Create Empty and then drag and drop it on the Project view. This wil create a Prefab that you can Instantiate.

To Instantiate a GameObject you need to call

Resources.Load("path_to_prefab")

The prefab needs to be under a folder called Resources. More on Resources.Load here.

Radu Diță
  • 13,476
  • 2
  • 30
  • 34
0

if its type is gameobject you can make a prefab out of it and then instantiate it if it isnt a gameobject then you can attach it to a gameObject make a prefab then instantiate the gameobject assign the prefab in inspector then use Instantiate

public GameObject prefab;
GameObject obj = Instantiate(prefab);
Milad Qasemi
  • 3,011
  • 3
  • 13
  • 17