Question by
VR27 · Nov 23, 2017 at 04:34 PM ·
c#scripting problem
increase score with a variable from another script
hi, how can i increase the score with a variable from another script? i tried diferent ways, but nothing work... i try to put the name of the script, ect so where is "count = count + 1;" i want to change the 1 for a variable from the athor script, cause not all objects have de same score, is that possible? can someone help? (and i didn´t put all the code here..)
`
public class OperateLitter : MonoBehaviour
{
public Transform hand;
private Transform holding;
public Text countText;
int count;
void Start ()
{
count = 0;
SetCountText ();
}
private void pegarObjecto (string tagLixo, string tagCaixote)
{
if (holding != null && hit.collider.gameObject.CompareTag (tagCaixote)) {
if (Input.GetMouseButtonDown (0) && holding.gameObject.CompareTag (tagLixo)) {
holding.parent = null;
holding.position = hit.collider.transform.position;
count = count + 1;
SetCountText ();
} else {
if (Input.GetMouseButtonDown (0)) {
Debug.Log ("Find the right Litter");
wrong_Ecoponto ();
}
}
}
}
}
void SetCountText ()
{
countText.text = "score: " + count.ToString ();
}
}
`
Comment
Best Answer
Answer by EDevJogos · Nov 23, 2017 at 04:43 PM
The Transform holding
is the transform of the object you want to get the value from? if so you can use count = count + holding.GetComponent<ClassName>().points
that's assuming you have a variable points
on the script of holding object.