Question by
T-Shirt_Games · May 28, 2017 at 01:55 PM ·
referenceintanother script
How do I reference int from other script
I am trying to make it so when I click on the object 3 times it will destroy it. This is the script attached to the player.
public Text MoneyText;
private int Money;
private int Clicks1;
public GameObject Base1;
public GameObject Basemake;
private Vector3 BaseSpot;
private bool basedeath;
public ClickScript clickscript;
void Start ()
{
MoneyText.text = "Money: " + Money;
Money = 0;
Clicks1 = clickscript.Clicks;
basedeath = true;
}
void Update()
{
BaseSpot = transform.position + Base1.transform.position;
if (Input.GetButtonDown ("Fire3"))
{
Instantiate(Basemake, BaseSpot, transform.rotation);
}
if (Clicks1 == 0)
{
if (basedeath)
{
Base1.gameObject.SetActive (false);
Money = Money + 1;
MoneyText.text = "Money: " + Money;
basedeath = false;
}
}
}
And this is the code attached to the object im trying to destroy
public int Clicks;
// Use this for initialization
void Start ()
{
Clicks = 3;
}
public void OnMouseDown ()
{
Clicks = Clicks - 1;
}
}
Comment
Your answer
Follow this Question
Related Questions
get all variables of a type from an object's components 0 Answers
[Help] how do I reference/access another script in unity C# 2 Answers
The name `FindObjectOfType' does not exist in the current context 2 Answers
NullReferenceException problems. 0 Answers
Launching local Unity API Reference from MonoDevelop on Linux 0 Answers