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");
TVController tvController = tvCanvas.gameObject.GetComponentInParent<TVController>();
if (tvController.IsUnlocked)
{
Transform insertTapeTransform = tvCanvas.transform.Find("InsertTape");
Transform descriptionTransform = tvCanvas.transform.Find("Description");
Transform titleTransform = tvCanvas.transform.Find("Title");
TextMeshProUGUI textTape = insertTapeTransform.gameObject.GetComponent<TextMeshProUGUI>();
textTape.text = "Play Tape";
descriptionTransform.gameObject.SetActive(false);
titleTransform.gameObject.SetActive(false);
}
}
public void InsertTape()
{
InventoryManager InvManager = FindObjectOfType();
GameObject tvCanvas = GameObject.Find("TVCanvas");
Transform insertTapeTransform = tvCanvas.transform.Find("InsertTape");
Transform noTapeTransform = tvCanvas.transform.Find("NoTape");
Transform descriptionTransform = tvCanvas.transform.Find("Description");
Transform titleTransform = tvCanvas.transform.Find("Title");
bool tapeInserted = false;
for (int i = 0; i < InvManager.MaxItems; i++)
{
if (InvManager.Slots[i].IsTaken == true)
{
Item ItemScript = InvManager.Slots[i].Item.GetComponent<Item>();
if (ItemScript.Name == "VHS Tape")
{
tapeInserted = true;
InvManager.RemoveItem(ItemScript.gameObject.transform, 1);
TextMeshProUGUI textTape = insertTapeTransform.gameObject.GetComponent<TextMeshProUGUI>();
textTape.text = "Play Tape";
descriptionTransform.gameObject.SetActive(false);
titleTransform.gameObject.SetActive(false);
TVController tvController = tvCanvas.gameObject.GetComponentInParent<TVController>();
tvController.IsUnlocked = true;
}
}
}
if (!tapeInserted)
{
insertTapeTransform.gameObject.GetComponent<TextMeshProUGUI>().text = "Insert Tape";
descriptionTransform.gameObject.SetActive(true);
titleTransform.gameObject.SetActive(true);
}
}
public void CheckForTape()
{
GameObject tvCanvas = GameObject.Find("TVCanvas");
TVController tvController = tvCanvas.gameObject.GetComponentInParent();
CheckRetroRelocate();
if (!tvController.IsUnlocked)
{
InventoryManager InvManager = FindObjectOfType();
Transform insertTapeTransform = tvCanvas.transform.Find("InsertTape");
Transform noTapeTransform = tvCanvas.transform.Find("NoTape");
GameObject insertTape = insertTapeTransform.gameObject;
GameObject noTape = noTapeTransform.gameObject;
bool foundTape = false;
for (int i = 0; i < InvManager.MaxItems; i++)
{
if (InvManager.Slots[i].IsTaken == true)
{
Item ItemScript = InvManager.Slots[i].Item.GetComponent<Item>();
if (ItemScript.Name == "VHS Tape")
{
foundTape = true;
insertTape.SetActive(true);
noTape.SetActive(false);
}
}
}
if (!foundTape)
{
insertTape.SetActive(false);
noTape.SetActive(true);
}
}
}
public void Exit()
{
MotionController motionController = FindObjectOfType();
CameraController camRig = FindObjectOfType();
if (camRig != null && motionController != null)
{
GameObject tvCanvas = GameObject.Find("TVCanvas");
if (tvCanvas != null)
{
tvCanvas.gameObject.SetActive(false);
camRig.ActivateMotor(9);
motionController.enabled = true;
}
}
}
}