- Home /
Display text when touching the ground two times?
So i am making my first game , its something like 2d volleyball .
I've made it so when the ball touches the ground it displays a text to restart the game. What i want to do is to display the text when it touches the ground Twice.
This is the script.
public bool groundContact = false;
public Transform ball;
private float groundRadius = 0.6f;
public LayerMask groundLayer;
public GUIText RestartText;
void Start ()
{
RestartText.text = "";
}
void FixedUpdate ()
{
groundContact = Physics2D.OverlapCircle (ball.position, groundRadius, groundLayer);
if (groundContact)
{
RestartText.text = "Press 'R' to Restart";
}
Comment
Answer by perchik · Mar 03, 2014 at 05:46 PM
Why don't you just keep a count of how many times it hits the ground, and if its 2, display the message?
int contactTimes;
void Start(){
contactTimes=0;
}
void FixedUpdate(){
...
if(groundContact){
contactTimes++;
}
if(contactTimes == 2){
//display message
}
}