Just like below, this is my script, it’s very strange that the public variables can’t all display in the inspector. It just displays “myScriptableObject” in the inspector but other public variables no matter what type and which it’s serializable. How can I solve this problem?
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class AttributesControl : MonoBehaviour
{
public MyScriptableObjects myScriptableObject;
public float randomMin;
public float randomMax;
public float attrMin;
public float attrMax;
}
My ScriptableObject just like this using UnityEngine; using System.Collections; using System; using System.Collections.Generic; [Serializable] public class MaterialsObject : ScriptableObject { [Serializable] public class Material : ScriptableObject { public int materialId; public string materialName; public int materialRarilty; } public List<Material> materialList; } Is this coding correct?
The ScriptableObject class is used to create seperate assets which aren’t gameobjects. If you declare a variable to a ScriptableObject you can only assign a ScriptableObject asset to that variable. Just like any other asset reference. ScriptableObjects have to be created explicitly in the editor and they can be edited seperately. Also ScriptableObjects have a similar restriction as MonoBehaviour classes. They also need to be placed in their own script file and have their filenames match the classname.
To me it looks like you actually don’t want to use ScriptableObjects here. Just use serializable classes:
[Serializable]
public class MaterialsObject
{
[Serializable]
public class Material
{
public int materialId;
public string materialName;
public int materialRarilty;
}
public List<Material> materialList;
}
While it’s possible to call your own class “Material” it will just cause problems with Unitys Material class.
Understood, but why I can't see any variables in the inspector? Looks like I removed all scripts and scriptableobjects then make a new script only includes one line code "public int test" and the default codes, it neither displays public variables at all.......I have no idea why this happens.......PS: I found something just now and looked like it will be useful, anyway, thanks a lot, man
@plumel very strange. I guess you have tried debugging every step? (as in, Debug.logError(other.gameObject.tag), Debug.logError(lives), Debug.logError(Player.tag)) If not you should do that to determine exactly where it won't run. Maybe the reference to the gameObject is wrong (doesn't seem like it though, sine Destroy(gameObject) won't work. What seems most likely is that you have a typo in the Tag. Do the shuriken have the Tag "shuriken" (notice all lower case letters)? Do the shuriken have a tag at all? Have you tried comparing the gameObject.name instead?
I have tried the debug logError and it is detecting the collision between the player and shuriken, however the Destroy(gameObject) didnt work in place of "Destroy (Player)"
My ScriptableObject just like this using UnityEngine; using System.Collections; using System; using System.Collections.Generic; [Serializable] public class MaterialsObject : ScriptableObject { [Serializable] public class Material : ScriptableObject { public int materialId; public string materialName; public int materialRarilty; } public List<Material> materialList; } Is this coding correct?
– KAMyAw