Question by
mindstormermage · Oct 03, 2016 at 06:20 PM ·
custom editor
Custom unity editor resetting values
Ok, I am very new to Unity custom editors. I do not understand how to stop unity from resetting my values.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class Weapon : MonoBehaviour {
public int attacknumber;
public bool isRanged = false;
public int range = 0;
//0 = sword basic
// Use this for initialization
void Start () {
try{
this.GetComponent <CircleCollider2D> ().enabled =false;
}
catch{
}
}
// Update is called once per frame
void Update () {
}
public void atk()
{
if (!isRanged) {
StartCoroutine (wait (1f));
}
}
IEnumerator wait(float x){
this.GetComponent <CircleCollider2D> ().enabled =true;
this.GetComponent <CircleCollider2D> ().radius = range;
yield return new WaitForSeconds(x);
this.GetComponent <CircleCollider2D> ().enabled =false;
}
void OnTriggerEnter2D(Collider2D other) {
//if (other.tag != "Player")
Debug.Log (other.name);
}
}
[CustomEditor(typeof(Weapon))]
[CanEditMultipleObjects]
[System.Serializable]
public class WeaponEditor : Editor
{
void Start()
{
}
override public void OnInspectorGUI()
{
var myScript = target as Weapon;
myScript.isRanged = GUILayout.Toggle(myScript.isRanged, "Is Ranged?");
if (myScript.isRanged) {
} else
{
myScript.range = EditorGUILayout.IntField ("Range", myScript.range);
}
}
}
How would I stop it from resetting values. I have searched all over including http://answers.unity3d.com/questions/507983/values-in-editor-script-resetting.html and many other places but I can not figure out how to use serialize field to stop it from resetting.
Comment
Your answer

Follow this Question
Related Questions
Import images from disk throught custom editor script. 0 Answers
Custom inspector ReorderableList gives an error when adding item to list 0 Answers
How to have Unity Cloud Build point to custom build call. 0 Answers
How to cast SerializedProperty back to custom class? 0 Answers
Custom OnSceneGUI-editor not working for ScriptableObjects? 2 Answers