Search Unity

displaying amount of objects fallen over

Discussion in 'Scripting' started by ammenter, May 22, 2019.

  1. ammenter

    ammenter

    Joined:
    May 16, 2019
    Posts:
    10
    I'm making a "game" kind of like bowling but I'm not sure how to display the score.
    currently, each time a pin falls over I get a ''Point'' in the console but I've been unsuccessful with getting the amount displayed on a 3d text object.
    Is this the best way to even do it or is there a smarter way to do it?
     
  2. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    Just store an integer value with the score and increase it every time you knock down a pin.

    Print that value to the text object, either on update or better even when you change the value
     
  3. ammenter

    ammenter

    Joined:
    May 16, 2019
    Posts:
    10
    Code (CSharp):
    1.  
    2.     void Update () {
    3.             if (transform.up.y < 0.5)
    4.             {
    5.                 ct.count = ct.count + 1;
    6.                 this.enabled = false;
    7.  
    I'm using this to store the value but I do not know how I can get It to print on a text object or a UI text which I've now tried
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    If your asking how to detect a fallen pin check the dot product of its 'transform.up' to global 'Vector3.up', leave some leeway(?) from perfectly up to the threshold where its counted as fallen.
     
  5. ammenter

    ammenter

    Joined:
    May 16, 2019
    Posts:
    10
    I got detecting it and storing the value under control I just can't figure out how to display it on a UI/3d text.
     
  6. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    1. Create a canvas
    2. Create a UI text element
    3. reference the text element to the script
    4.
    textElement.text = score.ToString()

    5. Do some research on referencing objects (its a basic thing you'll need to know about going forward using unity)
     
    Joe-Censored likes this.