Sprite Renderer makes my sprite dissapear..

Good morning guys…

I’m working through a course where the objective is to create a Color Switch game. However, I’ve run into a issue where when I created my sprite renderer to randomly change color, my sprite completely disappears…

I’m very new to unity and I don’t know what I’m doing wrong?? Everything work perfectly until I added the sprite renderer option to my player script…
(Pardon the big screen shots as I’m using a weird screen resolution…

```csharp
*using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour {

public string currentColor;
public float jumpForce = 10f;
public Rigidbody2D circle;
public SpriteRenderer sr;
public Color blue;
public Color yellow;
public Color pink;
public Color purple;

void Start () {
setRandomColor();

}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown(“Jump”) || Input.GetMouseButtonDown(0))
{
circle.velocity = Vector2.up * jumpForce;
}
}
void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log(collision.tag);
}
void setRandomColor()
{
int rand = Random.Range(0, 3);
switch (rand)
{
case 0:
currentColor = “blue”;
sr.color = blue;
break;
case 1:
currentColor = “yellow”;
sr.color = yellow;
break;
case 2:
currentColor = “pink”;
sr.color = pink;
break;
case 3:
currentColor = “purple”;
sr.color = purple;
break;
}
}
}*
```

Any help would be highly appreciated



In case you haven’t found it yourself yet, I think the problem is that the colors you set in the inspector have their alpha set to 0 which means fully transparent :slight_smile:

2 Likes