When I call the CheckRetroRelocate() method, i need another method that will change the text of a TextMeshProUGUI text. The text will contain a channel int, and a channelDescription string. Then if another TV isUnlocked true, add another TextMeshProUGUI text that will contain another TV specs. Beside the text, to the left, we will add a Toggle option, to choose a channel.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TVController : MonoBehaviour
{
public bool IsUnlocked { get; set; } //Unlock the Retro-Relocate functionnality
public int channel; //Unique ID/channel of the TV
public string channelDescription; //Short description of the channel for the UI
public Transform tvLocation; //The Location point when teleporting in
public void UnlockRetroRelocate()
{
IsUnlocked = true;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using com.ootii.Actors.AnimationControllers;
using com.ootii.Cameras;
public class TVCanvasController : MonoBehaviour
{
/public GameObject background;
public GameObject title;
public GameObject description;
public GameObject playTape;
public GameObject noTape;
public GameObject exit;/
public void CheckRetroRelocate()
{
GameObject tvCanvas = GameObject.Find("TVCanvas");
Here is a method UpdateChannelDescriptionText that will set the text of a TextMeshProUGUI element to contain a channel int and a channelDescription string. This method uses a list of TextMeshProUGUI elements to hold the channel descriptions and Toggles for each TV in the game. If any TV is unlocked, it will add a new TextMeshProUGUI element and Toggle to the list.
csharp
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ChannelDescriptions : MonoBehaviour
{
public List<TextMeshProUGUI> channelsTexts = new List<TextMeshProUGUI>();
public List<Toggle> toggles = new List<Toggle>();
public void UpdateChannelDescriptionText(TVController tv)
{
if (tv.IsUnlocked)
{
// Create a new TextMeshProUGUI object to hold the channel description
GameObject newTextObject = new GameObject("ChannelDescriptionText");
newTextObject.transform.SetParent(this.transform);
// Add a TextMeshProUGUI component and set the text
TextMeshProUGUI textComponent = newTextObject.AddComponent<TextMeshProUGUI>();
textComponent.text = "Channel " + tv.channel.ToString() + ": " + tv.channelDescription;
// Add the new text object to the list
channelsTexts.Add(textComponent);
// Create a new Toggle object to select the channel
GameObject newToggleObject = new GameObject("ChannelToggle");
newToggleObject.transform.SetParent(this.transform);
// Add a Toggle component and set it to the left of the text
Toggle toggleComponent = newToggleObject.AddComponent<Toggle>();
toggleComponent.transform.position = new Vector3(textComponent.transform.position.x - 50, textComponent.transform.position.y, textComponent.transform.position.z);
// Add the new Toggle object to the list
toggles.Add(toggleComponent);
}
}
}
You can call this method in the CheckRetroRelocate method of TVCanvasController class by first getting a reference to the ChannelDescriptions component and then calling UpdateChannelDescriptionText method: