I have 64000 text files in my Resources folder named Wave_Position_### with the numbers corresponding to the position of the object I put the script on. I want to change the transparency based on the text files. Unity freezes when I try to run the code. This exact code used to work. I don’t know what to do.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.IO;
using System.Security.Cryptography;
using System;
public class Wave : MonoBehaviour
{
public string[] lines;
public string myFile;
public Color color;
public Renderer rend;
string filePath, fileName;
// Start is called before the first frame update
void Start()
{
fileName = $"Wave_Position_{4*transform.position.x}_{4*transform.position.y}_{4*transform.position.z}";
// filePath = Application.dataPath + "/Wave_Position/" + fileName;
myFile = Resources.Load<TextAsset>(fileName).text;
lines = myFile.Split(',');
// lines = File.ReadAllLines(filePath).ToList();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space"))
{
StartCoroutine(Animation());
}
}
public IEnumerator Animation()
{
for (int i = 0; i <= 99; i++)
{
rend = GetComponent<Renderer>();
rend.enabled = false;
color = this.GetComponent<MeshRenderer>().material.color;
if (float.Parse(lines*) <= 0)*
{
rend.enabled = false;
}
else
{
rend.enabled = true;
color.a = 5float.Parse(lines);*
}
this.GetComponent().material.color = color;
yield return null; // new WaitForSeconds(1f);
}
}
}