Hello all
noob here
So currently my game looks like the picture I have attached. Basically different levels of force exerted on a sensor respond to different colours and textures(faces) on a sphere. I currently have four different levels, so four different colours, faces and times basically. What I want to do is change the amount of spheres in each level. And when the sensor is pressed each sphere changes from a plain white sphere to the face and colour of that level. So for example, in level 1 I want 4 spheres. And if the sensor is pressed once, 1 sphere will change to an angry red face and stay like that. Then when the sensor is pressed again, the next face changes to an angry red face and so forth. Then in the second level, I will have 3 spheres. When the sensor is pressed once, one sphere will change to a happy yellow face. When the sensor is pressed twice, another sphere will change to a happy yellow face and so forth. How would I go about doing this? I am currently feeling overwhelmed by the coding that this might entail. I have also attached the code to one of my levels so far:`
![using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
public class Arduino3 : MonoBehaviour
{
SerialPort sp = new SerialPort("\\\\.\\COM5", 9600);// Com port and the baud rate of the arduino
Material m_Material;
GameObject Sphere;
void Awake()
{
Sphere = GameObject.FindWithTag("Player");
m_Material = GameObject.FindWithTag("Player").GetComponent<Renderer>().material;
}
void Start()
{
if (!sp.IsOpen)
{ // If the erial port is not open
sp.Open(); // Open
}
sp.ReadTimeout = 250; // Timeout for reading
}
// Update is called once per frame
void Update()
{
if (sp.IsOpen)
{ // Check to see if the serial port is open
try
{
string portreading = sp.ReadLine(); // get the string output of the serial port
float amount = int.Parse(portreading);
if ((amount > 201f))
{
m_Material.color = Color.yellow;
Renderer _rend = Sphere.GetComponent<Renderer>();
Sphere.GetComponent<Renderer>().material = _rend.material;
_rend.material.mainTexture = Resources.Load("face3") as Texture;
}
else
{
m_Material.color = Color.white;
}
}
catch (System.Exception)
{
}
}
}
}
`][1]