0
0
Unityframework~10 mins

ScriptableObjects for game data in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a ScriptableObject class named ItemData.

Unity
public class ItemData : [1] {
    public string itemName;
    public int itemID;
}
Drag options to blanks, or click blank then click option'
AGameObject
BMonoBehaviour
CComponent
DScriptableObject
Attempts:
3 left
💡 Hint
Common Mistakes
Using MonoBehaviour instead of ScriptableObject.
Forgetting to inherit from any class.
2fill in blank
medium

Complete the code to create an instance of the ScriptableObject ItemData.

Unity
ItemData newItem = [1]<ItemData>();
Drag options to blanks, or click blank then click option'
AScriptableObject.CreateInstance
BInstantiate
CCreateObject
Dnew
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use 'new' keyword to create ScriptableObject.
Using Instantiate which is for GameObjects.
3fill in blank
hard

Fix the error in the code to save the ScriptableObject asset in the Unity Editor.

Unity
AssetDatabase.[1](newItem, "Assets/Data/NewItem.asset");
AssetDatabase.SaveAssets();
Drag options to blanks, or click blank then click option'
ACreateAsset
BCreateAssetInstance
CCreateAssetAtPath
DCreateAssetFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names that do not exist.
Forgetting to call SaveAssets after creating the asset.
4fill in blank
hard

Fill both blanks to create a dictionary from a list of ItemData where keys are item IDs and values are item names.

Unity
var itemDict = [1].ToDictionary(item => item.[2], item => item.itemName);
Drag options to blanks, or click blank then click option'
AitemsList
BitemsArray
CitemID
DitemName
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property for the key.
Using the wrong collection variable name.
5fill in blank
hard

Fill all three blanks to define a ScriptableObject with a CreateAssetMenu attribute and a public int field called 'value'.

Unity
[CreateAssetMenu(fileName = "[1]", menuName = "[2]")]
public class [3] : ScriptableObject {
    public int value;
}
Drag options to blanks, or click blank then click option'
ANewValue
BGame Data/Value Data
CValueData
DValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid class names or menu names.
Forgetting to match the class name with the file name.