Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Count

Discussion in 'Scripting' started by Timoty75, Jul 25, 2018.

  1. Timoty75

    Timoty75

    Joined:
    May 29, 2017
    Posts:
    150
    Hi boys are new of unity I would want to ask you a question: I have created a panel where there is a count when every time that an object destroys with tag through script, it increases the number. the problem and that (with the attached script) it doesn't increase the number to destroyed object. Can you help me? thanks a lot.




    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using System;
    5.  
    6. public class clickinv : MonoBehaviour
    7. {
    8.  
    9.    
    10.     int counter = 0;
    11.  
    12.     public GameObject uniqueButton;
    13.  
    14.     public Button myButton;
    15.     public Text scoreText;
    16.     public int score;
    17.     private object levelButton;
    18.  
    19.     public void ButtonClick()
    20.     {
    21.         counter++;
    22.     }
    23.  
    24.     // Use this for initialization
    25.     void Start()
    26.     {
    27.         myButton.interactable = false;
    28.         Button btn = myButton.GetComponent<Button>();
    29.         btn.onClick.AddListener(TaskOnClick);
    30.  
    31.     }
    32.  
    33.     void TaskOnClick()
    34.  
    35.  
    36.     {
    37.  
    38.         scoreText.text = "" + score;
    39.  
    40.         {
    41.             score--;
    42.  
    43.             if (score == 0)
    44.  
    45.  
    46.                 myButton.interactable = false;
    47.  
    48.             if (GameObject.FindWithTag("mace") == null)
    49.             {
    50.                 score++;
    51.              
    52.  
    53.  
    54.  
    55.  
    56.  
    57.  
    58.  
    59.             }
    60.  
    61.  
    62.         }
    63.     }
    64. }
    65.  
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Have you tried adding debug logging or a breakpoint to line 38 to check that the button click is working?