Hey everyone I have a problem. I tried many different methods to access the sprite’s color and change it upon collision. Nothing I tried is working
I tried the following
GetComponent().color = Color.red;
SpriteRenderer renderer = GetComponent();
renderer.color = new Color(0.5f, 0.5f, 0.5f, 1f);
The code I have is when the numberofhits equal a certain number it becomes that color, but I need to access the sprite Renderer to change the color.
Below is my function:
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "BlueBlock")
{
if (numberOfHits == 1)
{
SpriteRenderer renderer = GetComponent<SpriteRenderer>();
renderer.color = new Color(0.5f, 0.5f, 0.5f, 1f); // Set to opaque gray
}
}
}