- Home /
 
 
               Question by 
               MegaBlueBerry · May 08, 2020 at 01:10 AM · 
                guigameobjectbuttoncustom editorpropertydrawer  
              
 
              How do I make individual buttons change individual variables?
I have a property drawer that has two empty game objects and two buttons. how do I make a button instantiate an empty game object and put it in the variable space beside it?

these are my code
 using UnityEngine;
 
 [System.Serializable]
 public class ChunkScript
 {
     public GameObject topLeft;
     public GameObject bottomRight;
 }
 
               .
 using UnityEngine;
 
 [ExecuteAlways]
 public class MovementAreaScript : MonoBehaviour
 {
     [SerializeField]
     public ChunkScript[] chunks;
 }
 
               .
 using UnityEngine;
 using UnityEditor;
 
 [CustomPropertyDrawer(typeof(ChunkScript))]
 public class ChunkDrawer : PropertyDrawer
 {
     MovementAreaScript movementAreaScript;
 
     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
     {
         EditorGUI.BeginProperty(position, label, property);
 
         position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
 
         int indent = EditorGUI.indentLevel;
         EditorGUI.indentLevel = 0;
 
         Rect topLeftRect = new Rect(position.x, position.y, position.width * 0.25f, position.height);
         Rect leftButtonRect = new Rect(position.x + position.width * 0.25f, position.y, position.width * 0.25f, position.height);
         Rect bottomRightRect = new Rect(position.x + position.width * 0.25f * 2f, position.y, position.width * 0.25f, position.height);
         Rect rightButtonRect = new Rect(position.x + position.width * 0.25f * 3f, position.y, position.width * 0.25f, position.height);
 
         SerializedProperty topLeftProperty = property.FindPropertyRelative("topLeft");
        /// SerializedProperty leftButtonProperty = property.FindPropertyRelative("instantiateLeftGameObject");
         SerializedProperty bottomRightProperty = property.FindPropertyRelative("bottomRight");
         //SerializedProperty rightButtonProperty = property.FindPropertyRelative("instantiateRightGameObject");
        
         EditorGUI.PropertyField(topLeftRect, topLeftProperty, GUIContent.none);
         EditorGUI.PropertyField(bottomRightRect, bottomRightProperty, GUIContent.none);
 
         //if ( == null)
         //{           
             if (GUI.Button(leftButtonRect, "AddPoint"))
             {
                 //movementAreaScript.GetComponent
                 Debug.Log("Haliluha");
             }
         //}    
 
         if (GUI.Button(rightButtonRect, "AddPoint"))
         {
             Debug.Log("Haliluha but right");
         }
 
         EditorGUI.indentLevel = indent;
 
         EditorGUI.EndProperty();
     }
     public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
     {
         return base.GetPropertyHeight(property, label);
     }
 }
 
 
               
                 
                captureggggg.png 
                (9.4 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Bullet Prefab not instantiating 1 Answer
Char select / GUI button question. 3 Answers
Detect Click on Gameobject 0 Answers
Cube click pop-up menu 0 Answers
GameObject touchable instead GUI button 3 Answers