By JohnCabs
on Thu, 11/24/2022 - 04:20
Hello! I'm just a newbie so please bare with me. How can I call the object that show to my image target to my script? I create a script using a csv file that contains the information of the instruments (Name of the Instrument, Description, etc.).
Below you can see the my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
public class ReadData : MonoBehaviour
{
public TextAsset textAssetData;
private string Instrument;
private string Text;
public TextMeshProUGUI Name;
public TextMeshProUGUI Description;
public TextMeshProUGUI Dos;
public TextMeshProUGUI Uses;
// Start is called before the first frame update
void Start()
{
Instrument = "Mayo Table";
}
// Update is called once per frame
void Update()
{
Text = Instrument;
string[] data = textAssetData.text.Split(new string[] { ";", "\n" }, System.StringSplitOptions.None);
for (int i = 0; i < data.Length; i++)
{
if (Text == data[i])
{
Name.text = data[i];
Description.text = data[i + 1];
Dos.text = data[i + 2];
Uses.text = data[i + 3];
}
}
}
}
As you can see that the Instrument is equal to the variable that I put manually. What I want to happen is the Instrument is equal to the object that display.