so, i made a diolouge script aand it works but it’s a pain to work with so i was wondering if there was some way to simplify it so that way instead of having 4 arrays we can have less
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class DiolougeManager : MonoBehaviour
{
public string[] diolouge;
public string[] name;
public Sprite[] icon;
public bool[] isPlayer;
public Text talkArea;
public Text nameArea;
public Image characterOne;
public GameObject characterOneRoot;
public Image characterTwo;
public GameObject characterTwoRoot;
public int diolougeCurrentlyOn;
public string sceneToChangeTo;
public AudioSource audio;
// Start is called before the first frame update
void Start()
{
diolougeCurrentlyOn = 0;
audio.Play();
talkArea.text = diolouge[diolougeCurrentlyOn];
nameArea.text = name[diolougeCurrentlyOn];
if(isPlayer[diolougeCurrentlyOn]){
characterOneRoot.SetActive(true);
characterTwoRoot.SetActive(false);
characterOne.sprite = icon[diolougeCurrentlyOn];
}else{
characterOneRoot.SetActive(false);
characterTwoRoot.SetActive(true);
characterTwo.sprite = icon[diolougeCurrentlyOn];
}
}
public void NextTalk(){
if(diolougeCurrentlyOn >= (diolouge.Length - 1)){
SceneManager.LoadScene(sceneToChangeTo, LoadSceneMode.Single);
}else{
diolougeCurrentlyOn++;
audio.Play();
talkArea.text = diolouge[diolougeCurrentlyOn];
nameArea.text = name[diolougeCurrentlyOn];
if(isPlayer[diolougeCurrentlyOn]){
characterOneRoot.SetActive(true);
characterTwoRoot.SetActive(true);
characterOne.sprite = icon[diolougeCurrentlyOn];
}else{
characterOneRoot.SetActive(true);
characterTwoRoot.SetActive(true);
characterTwo.sprite = icon[diolougeCurrentlyOn];
}
}
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Return))
{
NextTalk();
}
}
}