Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GameObjects dynamically placed based on scriptableObject values

Discussion in 'Prefabs' started by JeffreyA, Sep 19, 2019.

  1. JeffreyA

    JeffreyA

    Joined:
    Jun 6, 2017
    Posts:
    17
    Hi,
    Thanks for opening my post and i know the title is maybe a bit confusing.
    I am just asking for some directions or articles that can help me cover this problem/question.

    I try to make a 3d isometric viewed puzzle game with blocks (cubes). Each cube can be clicked (selected) and than moves to the position of the next click on a ground plane. This works fine, but right now the cube can be move all over the plane which is 10 x 10.

    Situation:
    When a cube is selected it shows some ghost-cubes where it can be moved. This isnt a problem at all, but right now, every cube and ghostCube combination (example: a cube can move 1 grid up and 2 grid left, shown by the ghost-cubes next to the cube) has its own prefab. The next cube has 2 grids up and 1 right, thats another prefab. This is not how i want to build it.



    Here comes the part where i ask some directions or tutorials / examples:
    I thought i can make a scriptableObject called Cube, give it the up, down, right, left integers and than instantiate the ghost cubes on these positions (first example, cube spawns at 0, 0, 0, and ghost cube to the left spawns at -1, 0, 0). But is it possible and even "best practice" to spawn games objects based on scriptableObjects?
    Of course a instantiate-manager will read all the scriptableObjects and than builds the cubes at the desired positions.

    In short:
    All my cubes need to hold values where they need to spawn and where their ghost-cubes can spawn.
    How can i achieve this?