Advertisement
Frank84

Set value on add to scene

Feb 7th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. // Assets/Editor/TestEditor.cs
  2. using UnityEngine;
  3. using System.Collections;
  4. using UnityEditor;
  5.  
  6. [CustomEditor(typeof(Test))]
  7. public class TestEditor : Editor {
  8.  
  9.     private void Reset()
  10.     {
  11.         Debug.Log("Reset");
  12.         Test test = (Test)target;
  13.         test.SetVal(5);
  14.     }
  15. }
  16.  
  17.  
  18. // Assets/Test.cs
  19. using UnityEngine;
  20. using System.Collections;
  21.  
  22. public class Test : MonoBehaviour
  23. {
  24.     [SerializeField]
  25.     private int myVal;
  26.  
  27.     public void SetVal(int val)
  28.     {
  29.         myVal = val;
  30.     }
  31.  
  32.     private void Start()
  33.     {
  34.         Debug.Log("myVal: " + myVal);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement