Search Unity

my gameobject not turning to true

Discussion in 'Scripting' started by brunoenvia, Oct 27, 2019.

  1. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    94
  2. cmyd

    cmyd

    Joined:
    Oct 29, 2017
    Posts:
    98
    I don't you enabling/disabling the ball, All I see is in CountDown script you're destroying the ball.
     
  3. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Please use Code Tags and then paste the code here.
     
  4. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    94
    I'm not trying to disable the ball I'm trying to make the timer show on the screen
     
  5. cmyd

    cmyd

    Joined:
    Oct 29, 2017
    Posts:
    98
    In your StartCountDown function at the top Debug currentTime && timeLeft and another Debug in the if condition to see if it working.
     
  6. DominoM

    DominoM

    Joined:
    Nov 24, 2016
    Posts:
    460
    Is there a Rigidbody on the ball?

    https://docs.unity3d.com/Manual/CollidersOverview.html has a table of what combinations of colliders work together to fire events.

    You could rework your countdown script to do everything in the co-routine and instead of setting a flag on it, call countdown.StartCountdown(countdownSeconds)

    something like:
    Code (csharp):
    1.  
    2.    public void StartCountDown(float countdownSeconds)
    3.    {
    4.        showCountDown.SetActive(true);
    5.        showNumberCountDown.SetActive(true);
    6.        displayTimeText.text = ("Ball Destroying in: ");
    7.        StartCoroutine(DoCountDown(countdownSeconds));
    8.    }
    9.  
    10.    IEnumerator DoCountDown(float timeLeft)
    11.    {
    12.        while(timeLeft > 0.0f){
    13.            timeLeft -= Time.deltaTime;
    14.            numberCountDownText.text = Mathf.Round(timeLeft).ToString();
    15.            yield return null;
    16.        }
    17.        Destroy(ball);
    18.        yield return new WaitForSeconds(delayReloadingScene);
    19.        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    20.    }
    21.  
    Edit: sorry for all the edits.. kept hitting tab and accidentally saving while I was still typing :)
     
    Last edited: Oct 28, 2019
  7. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    94
    sorry i already fixed this
    i appreciate the help anyway :)
     
  8. cmyd

    cmyd

    Joined:
    Oct 29, 2017
    Posts:
    98
    Where was the problem?
     
  9. brunoenvia

    brunoenvia

    Joined:
    Aug 5, 2019
    Posts:
    94
    i was getting a component with getcomponent<CountDown> where the gameobject hadn't that
    component i had to findobjectoftype<CountDown>
     
  10. cmyd

    cmyd

    Joined:
    Oct 29, 2017
    Posts:
    98
    nice.