ScriptableObject

using UnityEngine;
using System.Collections;

[CreateAssetMenu(fileName = "Data", menuName = "Inventory/List", order = 1)]
public class MyScriptableObjectClass : ScriptableObject {
    public string objectName = "New MyScriptableObject";
    public bool colorIsRandom = false;
    public Color thisColor = Color.white;
    public Vector3[] spawnPoints;
}

3.67
6
Awgiedawgie 440220 points

                                    using UnityEngine;

[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/SpawnManagerScriptableObject", order = 1)]
public class SpawnManagerScriptableObject : ScriptableObject
{
    public string prefabName;

    public int numberOfPrefabsToCreate;
    public Vector3[] spawnPoints;
}

3.67 (6 Votes)
0
3.7
10
Awgiedawgie 440220 points

                                    using UnityEngine;

public class Spawner : MonoBehaviour
{
    // The GameObject to instantiate.
    public GameObject entityToSpawn;

    // An instance of the ScriptableObject defined above.
    public SpawnManagerScriptableObject spawnManagerValues;

    // This will be appended to the name of the created entities and increment when each is created.
    int instanceNumber = 1;

    void Start()
    {
        SpawnEntities();
    }

    void SpawnEntities()
    {
        int currentSpawnPointIndex = 0;

        for (int i = 0; i < spawnManagerValues.numberOfPrefabsToCreate; i++)
        {
            // Creates an instance of the prefab at the current spawn point.
            GameObject currentEntity = Instantiate(entityToSpawn, spawnManagerValues.spawnPoints[currentSpawnPointIndex], Quaternion.identity);

            // Sets the name of the instantiated entity to be the string defined in the ScriptableObject and then appends it with a unique number. 
            currentEntity.name = spawnManagerValues.prefabName + instanceNumber;

            // Moves to the next spawn point index. If it goes out of range, it wraps back to the start.
            currentSpawnPointIndex = (currentSpawnPointIndex + 1) % spawnManagerValues.spawnPoints.Length;

            instanceNumber++;
        }
    }
}

3.7 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
scriptableobjects unity unity create a script asset how to create a scriptable object in asset folder through script unity unity scriptableobject and scriptable objects scriptable objects script object unity add scriptable object to scene asset scriptableobject unity ScriptableObject.set is asset bundle a scriptableobject unity load or create scriptableobject asset unity export scene to asset bundle unity scene asset bundle how to open .assets file unity scriptable object create asset unity scriptableobject asset bundle unity scriptableobject just one asset unity find scriptableobject asset unity c# create scriptable object through code como usar scriptableobject unity create scriptableobject from code Unity EditorScript to create a scriptableObject unity c# scriptable object header scriptable objects c# scriptable object on create how to acsess data from scriptable objects unity what are scriptable objects unity scriptableobject using an asset unity create scriptableobject asset from code unity create scriptableobject with levelbuilder scriptable object unity c# unity create scriptable object in editor unity scriptableobject class unity scriptable object unity3d scriptableobject attribute unity c# scriptable objects read and write to scriptable object c# unity how to create a scriptableobject unity scriptable using scriptable objects in unity create a scriptble object create scriptable object unity in code create elements of scriptable object in unity c# scriptable objects open what is a scriptable object how to use scriptable objects to unity untiy 2019 how to open scriptable objects unity editor scriptableobject examples unity scripting object create scriptabele object in unity 2019 unity create scriptableobject in script scriptable ojbect to create catalog create scriptableObject unity unity create asset menue unity store object from project can you run code when you create a scriptable object asset scriptable object unity initialize how to add c# script to scriptable object unity unity create scriptableobject from script scriptable object string display unity editor create scriptableobject unity editor create and save scriptableobject new scriptable object create asset menu how to make a scriptable object unity sriptable objects unity crate asset menu scriptable objects in monobehaviour how to create scriptable object unity how to use scriptable objects unity scriptableobject editor tutorial create scriptableobject in editor unity editor create scriptableobject asset unity create scriptableobject asset structures of scripatble objects Unity scriptable object script setup unity editor add information to scriptableobject ScriptableObject example unity scritable object create asset menu unity unity tool create scriptableobject create new object from scriptableobject unity create new object from scriptable object unity how are unity scriptable objects stored unity new scriptableobject asset CreateAssetMenu unity unity createassetmenu unity create scriptableobject unity create assetmenu using scriptable object unity scriptableobject example open specific scriptable object yuntiy asset menu unity scriptable objects unity scriptable object in unity call CreateAssetMenu unity from code createassetmenu scriptable objects ScriptableObject unity what is scriptableobject the use of scriptable objects unity scriptable object unity scriptable object unity scriptable objects how to make scriptable object unity scriptable objects uniy unity scriptableobject unity create asset menu scriptable objects in scriptible oject unity what is a scriptable object in unity save data asset unity unity asset store creating scriptable objects c# unity how to get when a scriptable object is created
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source