hi guys,
so i have this problem:
i have two scripts, one is called Main.cs and the other GutterCheck.cs
im needing the following code frong Main.cs to add points to a variable in the in GutterCheck.cs
////// Main.cs
public class Main : MonoBehaviour {
private GutterCheck myGutterCheckScript;
void Start(){
myGutterCheckScript = new GutterCheck();
}
void Update () {
if ( Input.GetMouseButtonDown (0)){
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if ( Physics.Raycast (ray,out hit,100.0f)) {
if(hit.collider.tag == "enemy") {
print("---enemy hit");
myGutterCheckScript.updateScoreBoard(200);
}
}
}
}
}
this is what i have in GutterCheck.cs…
/////GutterCheck//////
public class GutterCheck : MonoBehaviour {
public int totalScore;
public void updateScoreBoard(int amount){
totalScore += amount; //add the amount that was passed to the score
print ("totalScore = " +totalScore);
}
}
My problem is that if i call the function from the Main.cs i get one lot of results and when i call the function from the GutterCheck i get an entirely new set of results
so for eg: when i call it from Main.cs the result will be 200, 400, 600 etc
when i call it from GutterCheck.cs i get 2, 4, 6, 8 etc
its not actually calculating it together which makes me think that it sees it as another variable or something but how do i fix this?
Cheers,