- Home /
Can you use multiple click functions with one script?
trying to set up multiple click functions from one script, then add that script to the various game objects. I am trying to set up a script that checks if variable 1, in this case its called techpoints in my script. if they have 50 I want to be able to buy a virus and subtract those points. I got it working, but i realized that i had to keep inheriting back to check for the variables that i was using as the currency to purchase the new ones. I thought it might be easier to set it all up in one script, but when i did that nothing seems to work. I added the scrip to the 2 different game objects, and selected the different variables on each one. here is my script. can anyone tell me what im doing wrong, or if there is a much better way to do this?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class BuildVirus : TPB {
// public UnityEngine.UI.Text TPC;
public UnityEngine.UI.Text TechPoints;
public static float techPoints = 0.00f;
public float techPointsPerClick = 1;
// private Slider mySlider;
// public float counter = 10.0f;
public int click;
public int VirusCost ;
// public VirusClick click;
// public UnityEngine.UI.Text vpc;
public UnityEngine.UI.Text VirusCount;
public float virus = 0.00f;
public int virusPerClick = 1;
void Start(){
}
void Update(){
// VirusCount.text = "Virus Count: " + virus;
// TechPoints.text = "Tech Points: " + techPoints;
// vpc.text = "VPC: " + virusPerClick;
Debug.Log ("techPoints:" + techPoints);
}
public void Clicked(){
VirusCost = 50;
// Debug.Log("techPoints before:"+techPoints);
if(techPoints >= VirusCost){
techPoints -= VirusCost;
virus += 1;
}
// Debug.Log("techPoints after:"+techPoints);
}
public void TechPointsClicked(){
techPoints += techPointsPerClick;
{
}
}
}
I was going through my game outline, and realized that it might work best if i just make one script that has all the variables defined, and then anytime i make a new one i can have it inherit from that first script, and then have the first one inharit monobehaviour, would that be the best option?
hmm.. that seems to still bring up all the options on the editor interface still. not sure, what do i try? lol
To make variables public that you can access in other scripts but don't want to be visible in the editor, type this directly above the variable [HideInInspector].