Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Having 2 SetCountText don't work?

Discussion in 'Scripting' started by JACKO4590, Nov 25, 2014.

  1. JACKO4590

    JACKO4590

    Joined:
    Nov 25, 2014
    Posts:
    81
    ok well i have a count that counts all of the cubes i pick up, i tried making a second one for the reason i want to have 2 lists. one does the main cubes and the other dose another set of cube(s)

    this is what i have atm

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class _PlayerControlls : MonoBehaviour
    5. {
    6.    
    7.     public float speed;
    8.     public GUIText countText;
    9.     public GUIText winText;
    10.     public GUIText restartText;
    11.     public GUIText nextLevel;
    12.     public GUIText timeCount;
    13.     public GUIText bestTime;
    14.     public GUIText winText2;
    15.     public GUIText secretpickup;
    16.     public GUIText countText2;
    17.  
    18.     public int time;
    19.    
    20.     private int count;
    21.     private int count2;
    22.     private bool restart;
    23.     private bool NextLevel;
    24.     private bool NextLevel2;
    25.    
    26.     void Start ()
    27.     {
    28.         count = 0;
    29.         count2 = 0;
    30.         SetCountText ();
    31.         SetCountText2 ();
    32.         secretpickup.text = "";
    33.         winText.text = "";
    34.         winText2.text = "";
    35.         restart = true;
    36.         NextLevel = false;
    37.         NextLevel2 = false;
    38.         restartText.text = "Falling? press 'R' for restart";
    39.         nextLevel.text = "";
    40.  
    41.        
    42.     }
    43.    
    44.     void Update ()
    45.     {
    46.         if (restart)
    47.         {
    48.             if (Input.GetKeyDown (KeyCode.R))
    49.             {
    50.                 Application.LoadLevel (Application.loadedLevel);
    51.             }
    52.         }
    53.         {
    54.             if (NextLevel)
    55.             {
    56.                 if (Input.GetKeyDown (KeyCode.F))
    57.                 {
    58.                     Application.LoadLevel ("RollerBall1");
    59.                 }
    60.             }
    61.         }
    62.         {
    63.             if (NextLevel2)
    64.             {
    65.                 if (Input.GetKeyDown (KeyCode.Q))
    66.                 {
    67.                     Application.LoadLevel ("RollerBall3");
    68.                 }
    69.             }
    70.         }
    71.     }
    72.    
    73.     void FixedUpdate ()
    74.     {
    75.         float moveHorizontal = Input.GetAxis("Horizontal");
    76.         float moveVertical = Input.GetAxis("Vertical");
    77.  
    78.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    79.        
    80.         rigidbody.AddForce(movement * speed * Time.deltaTime);
    81.     }
    82.    
    83.     void OnTriggerEnter(Collider other)
    84.     {
    85.         if (other.gameObject.tag == "PickUp")
    86.         {
    87.             other.gameObject.SetActive(false);
    88.             count = count + 1;
    89.             SetCountText ();
    90.             audio.Play ();
    91.         }
    92.         if (other.gameObject.tag == "PickUp2")
    93.         {
    94.             other.gameObject.SetActive(false);
    95.             count2 = count2 + 1;
    96.             SetCountText2 ();
    97.             audio.Play ();
    98.         }
    99.     }
    100.    
    101.     void SetCountText ()
    102.     {
    103.         countText.text = "Count: " + count.ToString();
    104.         if (count >= 35)
    105.         {
    106.             winText.text = "YOU WIN THIS ROUND!";
    107.             winText2.text = "Maybe you missed something? Maybe there is a secret somewhere? (ツ)";
    108.             restartText.text = "Press 'R' for Restart";
    109.             restart = true;
    110.             nextLevel.text = "Press 'F' for NextLevel";
    111.             NextLevel = true;
    112.         }
    113.     }
    114.  
    115.     void SetCountText2 ()
    116.     {
    117.         countText2.text = "Count2: " + count.ToString ();
    118.         if (count2 >= 1)
    119.         {  
    120.             secretpickup.text = "Wow you found a secret. Press 'Q' for secret Level";
    121.             NextLevel2 = true;
    122.         }  
    123.     }
    124.  
    125.     void UpdateTime ()
    126.     {
    127.         timeCount.text = "time " + Time.deltaTime;
    128.     }
    129. }
    iv add void SerCountText2 and all that so i pretty much copied the first one and put 2's on the end so they dont collide but my problem is i go and pick up a normal cube and it adds up like its meant to but when i pick up my other cube with tag PickUp2 if will add how many normal cubes i have picked up and add it on Counttext2.text

    Anyway to have 2 different counts?
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. JACKO4590

    JACKO4590

    Joined:
    Nov 25, 2014
    Posts:
    81
    was there a reason you quoted me and not put anything in? have i missed something? im still new to this but have a basic understanding of the codes used in the tutorials as thats what im using to add more onto mine

    EDIT: nvm i got it, i looked at what you quoted and thought if i add a '2' after count in count.ToString it might work and it did, thanks for that, cause now i can add multi secret cubes :D