Checking another script for a statement?

So I am currently trying to grab the score from an object to see if it’s more than something, and I can not seem to do that, I had a massive issue with trying to get it to access the objects code the first time around, but I seem to have fixed that somehow.

Now I added the same line of code to another object and yet I am unable to get it working, I fixed most of the issues with the code, but I am still running into some issues since my code doesn’t seem to be working when it comes to checking if it’s true or not.

using UnityEngine;
using System.Collections;

public class BuyingTower : MonoBehaviour{


    public MotherController motherController;
    public int scoreValue;
    public GameObject tower1;
    public Transform buttonplace;


void Start ()
    {
        GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
        if (gameControllerObject != null)
        {
            motherController = gameControllerObject.GetComponent <MotherController>();
        }
        if (motherController == null)
        {
            Debug.Log ("Cannot find 'motherController' script");
        }
    }

    public void ButtonPosition(){
        getposition = transform.GetComponent<RectTransform>().position;
    }

    void Update ()
    {
        Input.GetKeyDown("Fire1");
        {
            if motherController.score >= 20;
            {
                MotherController.RemoveScore (scoreValue);
                Instantiate(tower1, buttonplace.getposition = transform.GetComponent<RectTransform>().position, buttonplace.getposition = transform.GetComponent<RectTransform>().position);
            }
        }
    }
}

The main issue I have is with this little bit;

    void Update ()
    {
        Input.GetKeyDown("Fire1");
        {
            if motherController.score >= 20;
            {

It works fine with adding the AddScore and that, so it’s finding the actual object, I simply can not get the if statement to work and actually check…

Here’s the code for the MotherController;

using UnityEngine;
using System.Collections;

public class MotherController : MonoBehaviour
{
        public GameObject Enemies;
        public Vector3 spawnValues;
        public int hazardCount;
        public float spawnWait;
        public float startWait;
        public float waveWait;
       
    public GUIText scoreText;
    private int score;

        void Start ()
        {
        score = 0;
        UpdateScore ();

            StartCoroutine (SpawnWaves ());
        }
       
        IEnumerator SpawnWaves ()
        {
            yield return new WaitForSeconds (startWait);
            while (true)
            {
                for (int i = 0; i < hazardCount; i++)
                {
                    Vector3 spawnPosition = new Vector3 (spawnValues.x, spawnValues.y, spawnValues.z);
                    Quaternion spawnRotation = Quaternion.identity;
                    Instantiate (Enemies, spawnPosition, spawnRotation);
                    yield return new WaitForSeconds (spawnWait);
                }
                yield return new WaitForSeconds (waveWait);
            }
        }


    void Update ()
    {

    }

    public void AddScore (int newScoreValue)
    {
        score += newScoreValue;
        UpdateScore ();
    }


    public void RemoveScore (int newScoreValue)
    {
        score -= newScoreValue;
        UpdateScore ();

    }
    void UpdateScore ()
    {
        scoreText.text = "Money: " + score;
    }
   
    }

Now I know it’s a bloody mess, but I’l get to cleaning it up later, right now I am simply trying to understand why it will not work, most commented code is just code that I am yet to actually clear out.

Anyone have any idea how I could solve this? :confused:

void Update ()
    {
        Input.GetKeyDown("Fire1");   /// missing if statement
        {
            if motherController.score >= 20;  /// look at the other if statements in your code, they have bracket, why doesn't this??
            {
                MotherController.RemoveScore (scoreValue);
                Instantiate(tower1, buttonplace.getposition = transform.GetComponent<RectTransform>().position, buttonplace.getposition = transform.GetComponent<RectTransform>().position);
            }
        }
    }

I tried to use an if statement, but it would simply give me more errors than help, as for when it comes to brackets, they simply added ontop of my other error message, removing them simply got rid of the error message.

It was something along the lines of “Unexpected symbol if', expecting ;'”

Which to me made little sense so I just got rid of it.

in which case you aren’t fixing the problems, just moving the error around.

Line 4 in my snippet above needs to be encased in an if statement. line 6 needs to be a properly formatted if statement.

That’s not the issue, that is not giving me an error message, I am getting an issue trying to get ahold of ‘motherController.Score’, secondly adding brackets to if statement just breaks everything…

I am now getting errors on my “getposition” code which for some reason was fine before adding brackets. I am so confused…

getposition isn’t a function of the transform class, and that isn’t how you pass parameters into the instantiate function.

If the compiler runs into an error it stops, so to start with it gets as far as the “if issue” and stops, complaining about them, when you fix them it can get past that and runs into the next error, and then complains about that. Just because it didn’t complain about the getposition code when it was complaining about the if lines doesn’t mean they were “fine” it just means it couldn’t get that far.

You need to correctly form the syntax for each line, else it will return errors as it reaches them one by one.

Use the scripting reference to find out what the correct syntax is:

etc.

if you are really struggling with the basics you should check out the tutorials:

Thank you for your help, I managed to fix the if and input, it was just me clearly being a fool thank you for pointing that out, I fiddles about with my code and am now creating the object where the mouse is at, I am using;

        if (Input.GetKeyDown("Fire1"));
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (motherController.score >= 20);                   
                    {
                    Instantiate(tower1, transform.position, transform.rotation);
                    MotherController.RemoveScore (scoreValue);
                    }
            }

But with that done, I have ran into another issue, this being an issue with; “An object reference is required to access non-static member” now, I am using the exact same code for the AddScore and that is having no issues what soever, the only difference is that I am trying to take away points, it’s set up the same way as AddScore as you can see on the MotherController code.