Hi there,
So for my project, an aspect is that I want to change 1 specific GameObjects color to match the one singled out. There aren’t any errors and I’m able to run the game. It just doesn’t change the color though. I’ve placed a standard Unity cube to see if it should work ( Since I thought the possibility of me using a sprite/imported object would be a problem ) but it still doesn’t do anything.
This all has to happen while the game is running, as this would be on an infinite loop if the player can keep progressing on.
My code is
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColorArray : MonoBehaviour
{
public GameObject[] CirclePart;
public int activeCircle;
public GameObject Arrow;
public GameObject ColorGrabber;
// Start is called before the first frame update
void Start()
{
NewCircle();
}
// Update is called once per frame
void Update()
{
}
void NewCircle()
{
activeCircle = Random.Range(0, CirclePart.Length);
ColorGrabber = CirclePart[activeCircle];
Color thisColor = ColorGrabber.GetComponent<SpriteRenderer>().material.GetColor("_Color");
GetComponent<SpriteRenderer>().material.color = thisColor;
Arrow.GetComponent<SpriteRenderer>().material.SetColor("_Color", thisColor);
}
}
If you’ve got an idea as to why this is, your help is very appreciated.