Answer the question
In order to leave comments, you need to log in
Why does the ball disappear?
I'm trying to make the ball at startup have a random color, the color changes (you can see it in the inspector), but the ball disappears completely,
public class PlayerController : MonoBehaviour
{
public float jumpForce=10f;
public Rigidbody2D rb;
public string CurrentColor;
public SpriteRenderer sr;
public Color ColorGreen;
public Color ColorBlue;
public Color ColorRed;
public Color ColorOrange;
// Start is called before the first frame update
void Start()
{
SetRandomColor();
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Jump")|| Input.GetMouseButtonDown(0))
{
rb.velocity=Vector2.up* jumpForce;
}
}
private void OnTriggerEnter2D(Collider2D other) {
Debug.Log(other.tag);
}
private void SetRandomColor()
{
int index=Random.Range(0,3);
switch(index)
{
case 0:
CurrentColor="green";
sr.color=ColorGreen;
break;
case 1:
CurrentColor="blue";
//sr.color=ColorBlue;
sr.color=ColorGreen;
break;
case 2:
CurrentColor="red";
// sr.color=ColorRed;
sr.color=ColorGreen;
break;
case 3:
CurrentColor="orange";
// sr.color=ColorOrange;
sr.color=ColorGreen;
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question