How can i create primitive my own prefab ?

private void Draw()
        {
            // get reference to the TileMap component
            var map = (TileMap)this.target;

            // Calculate the position of the mouse over the tile layer
            var tilePos = this.GetTilePositionFromMouseLocation();

            var prefab = map.Prefab;
            // Given the tile position check to see if a tile has already been created at that location
           prefab = GameObject.Find(string.Format("Tile_{0}_{1}", tilePos.x, tilePos.y));

            // if there is already a tile present and it is not a child of the game object we can just exit.
            if (prefab != null && prefab.transform.parent != map.transform)
            {
                return;
            }

            // if no game object was found we will create a cube
            if (prefab == null)
            {
                prefab = GameObject.CreatePrimitive(PrimitiveType.Cube);
            }

This will create Cube/s all the time.
I want to create the variable prefab.

In the map script at the top i did:

public GameObject Prefab;

So no the prefab is not a cube but something else.
How can i create now what is in prefab and not a cube ?

In the examples you’ll notice you can type that prefab as any UnityEngine.Object type. So if you want to create a Prefab with a ‘Missile’ script attached to it. And you want to force your spawn script so that it only spawns ‘Missile’ prefabs. You type the variable as ‘Missile’, and only prefabs with ‘Missile’ scripts on it can be assigned there.

1 Like

Thanks.