Search Unity

Adding +1 Points Every Time Button Clicks

Discussion in 'Scripting' started by Steelshot, Apr 24, 2016.

Thread Status:
Not open for further replies.
  1. Steelshot

    Steelshot

    Joined:
    Feb 24, 2015
    Posts:
    102
    Hi,

    I am trying to code a script that will allow me to add 1 subscriber per every
    click of the Upload button, here is a picture of what i'm talking about.

    Here's my script so far:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;

    public class Button : MonoBehaviour {

    int AddSubs = 0;

    public void AddToSubs(){
    AddSubs += 1;
    GetComponent<Text>().text = "Subscribers:" + AddSubs;
    }
    }

    Please help!
     
  2. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    Have you activated the button so it works on click?

    throw Debug.log(Addsubs);

    in the update to see if it's being added
     
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    "get the text component on the current gameobject"... I'd say it's a fair bet this script isn't on the displaying text gameobject.
     
  4. Steelshot

    Steelshot

    Joined:
    Feb 24, 2015
    Posts:
    102
    Yeah it isn't, but when ever i add a public Text Subscribers; and drag and drop the subscribers text into the field it doesn't work either
     
Thread Status:
Not open for further replies.