Question by
potatoqueue · Jan 22, 2017 at 09:05 PM ·
colorgame objectcsv
I don't know how to set the colour of a game object from a csv file?
I have a single line text file with comma separated values from 0-255 that i want to apply to an object to change its colour at runtime, not sure where i am going wrong? Also the values are all greyscale
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.IO;
public class csvreader02 : MonoBehaviour { public GameObject planeTest; //public object to add public TextAsset csvFile; // csv file txt to add
// Update is called once per frame
void Update () {
readCSV(); //execute read function
}
void readCSV()
{
string [] records = csvFile.text.Split('\n');
for(int i=0; i < records.Length; i++)
{
string [] fields = records[i].Split(',');
planeTest.GetComponent<Renderer>().material.color = Color(float.Parse(fields[0]),float.Parse(fields[0]),float.Parse(fields[0]));
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How can I change the alpha value of multicolored text to 0? 1 Answer
Get color between 2 colors 0 Answers
I can't change Text color 3 Answers
How to store colors data? 0 Answers
Need help to make a color replace shader 0 Answers