PLEAASEE I NEED HELP!!! How to turn Mesh Renderer of cubes on and off by pushing buttons?

Hi everyone,

Please help me with this. I want to enable and unenable the meshrender of the cubes by pushing “e” and “u” buttons, but it didnt work. Everytime I pushed those button nothing happens. I don’t know how to fix it (T…T)

The code is as below. What I did was that I extracted positions and colors of the cubes from a csv file. (I cant upload the csv file, I upload the txt file instead in case that if you need the file to run you can change it back to csv file).


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Transparent : MonoBehaviour
{
    public TextAsset CSV;
    public GameObject Cube;
    public static bool click = true;
    // Start is called before the first frame update
    void Start()
    {
        string[] myCSV = CSV.text.Split('

‘);
for (int i = 0; i < myCSV.Length; i++)
{
// Positions of the Cubes
GameObject myCube = GameObject.Instantiate(Cube);
string values1 = myCSV*.Split(’,');*
float x = float.Parse(values1[0]); // column 1 of the csvfile
float y = float.Parse(values1[1]); // column 2 of the csvfile
float z = float.Parse(values1[2]); // column 3 of the csvfile
myCube.transform.position = new Vector3(x, y, z);

// Colors of the Cubes
float r = float.Parse(values1[3]); // column 4 of the csvfile
float g = float.Parse(values1[4]); // column 5 of the csvfile
float b = float.Parse(values1[5]); // column 6 of the csvfile
Renderer myrend = myCube.GetComponent();
myrend.material.color = new Color32((byte)r, (byte)g, (byte)b, 255);

//MeshRenderer of the Cubes
MeshRenderer cubeMeshRenderer = myCube.GetComponent();
cubeMeshRenderer.enabled = click;

}

}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(“e”))
{
click = true;
}
else if (Input.GetKeyDown(“u”))
{
click = false;
}
}
}
[156511-mixed.txt|156511]*
*

public class Transparent : MonoBehaviour
{
public TextAsset CSV;
public GameObject Cube;
private Renderer cubes;

     // Start is called before the first frame update
     void Start()
     {
         string[] myCSV = CSV.text.Split('

');
cubes = new Renderer[myCSV.Length];

         for (int i = 0; i < myCSV.Length; i++)
         {
             // Positions of the Cubes
             GameObject myCube = GameObject.Instantiate(Cube);
             string[] values1 = myCSV*.Split(',');*

float x = float.Parse(values1[0]); // column 1 of the csvfile
float y = float.Parse(values1[1]); // column 2 of the csvfile
float z = float.Parse(values1[2]); // column 3 of the csvfile
myCube.transform.position = new Vector3(x, y, z);

// Colors of the Cubes
float r = float.Parse(values1[3]); // column 4 of the csvfile
float g = float.Parse(values1[4]); // column 5 of the csvfile
float b = float.Parse(values1[5]); // column 6 of the csvfile
Renderer myrend = myCube.GetComponent();
myrend.material.color = new Color32((byte)r, (byte)g, (byte)b, 255);

//MeshRenderer of the Cubes
cubes = myCube.GetComponent();
}
}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(“e”))
{
foreach(Renderer cube in cubes)
cube.enabled = true ;
}
else if (Input.GetKeyDown(“u”))
{
foreach(Renderer cube in cubes)
cube.enabled = false ;
}
}
}