- Home /
Material Sphere Green
I designed a basketball game. I made seven balls called "sphere". I want the bottom "sphere" to be green when there is a top basket.
Are you saying you want each ball that goes into the hoop turn green? Wherever you increase your score, change the ball color to green. You'd have to post your code for me to be more precise...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Skor : $$anonymous$$onoBehaviour {
public Text displaytext;
private int count;
private void Start()
{
count = 0;
displaytext.text = "Score : " + count.ToString();
}
void OnTriggerEnter2D (Collider2D other)
{
if(other.gameObject.CompareTag("basket"))
{
count=count + 10;
displaytext.text = "Score : " + count.ToString();
}
}
private void Update()
{
}
}
Just add one line: void OnTriggerEnter2D (Collider2D other) { if(other.gameObject.CompareTag("basket")) { count=count + 10; displaytext.text = "Score : " + count.ToString(); other.GetComponent<$$anonymous$$eshRenderer>().material.color = Color.green;
}
}
Answer by dan_wipf · Jul 30, 2018 at 05:14 PM
change the color of the material? material.color = color.green;
i guess its an ui element. you have to make a refrence to when the ball hits a score. maybe a boolean like: if(ballscores == true){ material.color = color.green;} if(ballnoscore ==true) {material.color = color.red;}
but best would be if you post your scripts here for a detailed answer.
regards dan