Search Unity

GUILayout.Button problems

Discussion in 'Scripting' started by bogdanTNT, Jul 15, 2020.

  1. bogdanTNT

    bogdanTNT

    Joined:
    Oct 28, 2018
    Posts:
    5
    Hey guys. I wanted to make a system that added a new gameobject to a list. The specific gameobject is assigned to a gui button in the editor. But every time a press the button in the editor I get an error.


    Send help pls


    Code (CSharp):
    1. public class DialogNPC : MonoBehaviour
    2. {
    3.     public GameObject[] speaker;
    4.  
    5.     public List<Converation> conv;
    6.     public Choises[] choises;
    7.  
    8.    
    9.  
    10.     int nrOfConv;
    11.     bool backAndForth = true;
    12.  
    13.     //private AudioSource[] speakersAudio;
    14.  
    15.     Converation con;
    16.     public void makeConvForSpeaker(GameObject speaker)
    17.     {
    18.         con.who = speaker;
    19.         conv.Add(con);
    20.     }
    21. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. [CustomEditor(typeof(DialogNPC))]
    7. public class DialogSystemEditor : Editor
    8. {
    9.     public override void OnInspectorGUI()
    10.     {
    11.         base.OnInspectorGUI();
    12.  
    13.         DialogNPC npc = (DialogNPC)target;
    14.  
    15.         for (int i = 0; i < npc.speaker.Length; i++)
    16.             if (GUILayout.Button(npc.speaker[i].name))
    17.                 npc.makeConvForSpeaker(npc.speaker[i]);
    18.  
    19.  
    20.     }
    21. }
    22.  

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Converation : MonoBehaviour
    6. {
    7.     public string theLine;
    8.     public GameObject who;
    9.     public AudioClip audio;
    10. }
    11.  
     
  2. bogdanTNT

    bogdanTNT

    Joined:
    Oct 28, 2018
    Posts:
    5


    This is the error btw

    Thanks