This function is called when the ScriptableObject script is started.
Awake is called as the ScriptableObject script starts. This happens
as the game is launched and is similar to MonoBehavior.Awake.
An example is given below. This example has two scripts. The first shown is the ScriptableObject
script. This implements code which is separate from MonoBehaviour. The second is a small
MonoBehaviour related script which accesses values from the ScriptableObject script.
#pragma strict
// A ScriptableObject example script. // The A and B members implement features which // are unrelated to MonoBehaviour.
public class ScriptObj extends ScriptableObject {
private var a: int = 10; private var b: int[] = [0, 17, 34, 42, 67];
public var A: int = a;
// return value in b array, or -1 if x is out-of-range public function B(x: int) { if (x >= 0 && x <= 5) return b[x]; else return -1; }
public function Awake() { Debug.Log("Awake"); }
public function OnDestroy() { Debug.Log("OnDestroy"); } }
// A ScriptableObject example script. // The A and B members implement features which // are unrelated to MonoBehaviour.
using UnityEngine;
public class ScriptObj : ScriptableObject { int a = 10; int[] b = new int[5] {0, 17, 34, 42, 67};
public int A { get {return a; } }
// return value in b array, or -1 if x is out-of-range public int B(int x) { if (x >= 0 && x <= 5) return b[x]; else return -1; }
public void Awake() { Debug.Log("Awake"); }
public void OnDestroy() { Debug.Log("OnDestroy"); } }
The following script makes use of the above ScriptableObject script.
#pragma strict
public class ScriptObjExample extends MonoBehaviour {
function Start() {
var test : ScriptObj = ScriptableObject.CreateInstance("ScriptObj") as ScriptObj;
print(test.A); print(test.B( 3)); print(test.B(-3)); } }
// create and access the ScriptObj
using UnityEngine;
public class ScriptObjExample : MonoBehaviour { ScriptObj test;
void Start() { test = (ScriptObj)ScriptableObject.CreateInstance(typeof(ScriptObj));
print(test.A); print(test.B(3)); print(test.B(-3)); } }
Did you find this page useful? Please give it a rating: