- Home /
 
Factory script not working
Hello,
I am currently making a small factory with a cube collider trigger. When the player touches this trigger, it pops up a GUI menu on screen. If the player clicks the 'Refine Rocks' button it will run a function called RefineRocks that has a for loop. That for loop takes the static int rocks from the player class and subtracts from it until it has 0 and for each subtraction from rocks it adds to static int iron on the player class.
However it doesn't seem to work, I can't even get the Debug.Log();statement to show up in console.
Can anyone help me get this working? Here is the script:
Player Class:
 using UnityEngine;
 using System.Collections;
 
 public class PlayerClass : MonoBehaviour {
     
     //Basic Player Floats
     public float playerHealth;
     public static float playerOxygen;
     public static int rocks = 5;
     public static int iron = 0;
     
     //Basic Player Bools
     public bool playerIsDead;
     public bool playerIsOxyless;
     
     //Extra Bools
     public bool playerWeaponOut;
     
     //Transforms, Vectors, and Rays
     public Transform playerPos;
     public RaycastHit playerHit;
     public Vector3 playerFacingDir;
     
     void HealthCheck () {
         if(playerHealth <= 0){
             playerIsDead = true;
         }
     }
 
     //Checks if player is Starving, thirsty, etc.
     void NeedsCheck () {
         if(playerOxygen <= 0){
             playerIsOxyless = true;
         }
     }
     
     //What happens if one of the above conditions is true...
     void PlayerEffects () {
         if(playerIsOxyless != false){
             playerHealth -= Time.deltaTime;
         }
     }
 
     void PlayerDeath(){
         if(playerIsDead != false){
             Destroy(gameObject);
         }
     }
     
     // Use this for initialization
     void Start () {
         HealthCheck();
         playerOxygen = 100;
     }
     
     // Update is called once per frame
     void Update () {
         PlayerEffects();
         HealthCheck();
         NeedsCheck();
         OxySubtract();
     }
     
     //Oxygen
     void OxySubtract() {
         if(LMRegen.regenON == false){
             playerOxygen -= Time.deltaTime / 2;
             if(playerOxygen < 0){
                 playerOxygen = 0;
             }
         }
     }
     
     void OnGUI() {
         GUI.Box(new Rect(0, 60, 100, 25), "Oxygen");
         GUI.Box (new Rect(0, 90, playerOxygen, 30), " ");
         GUI.Label(new Rect(35, 90, 100, 100), playerOxygen.ToString("f0"));
     }
 }
 
 
               Factory Class:
 using UnityEngine;
 using System.Collections;
 
 public class Factory : MonoBehaviour {
 
     private bool showGUI;
     private bool clickedRock;
     public int rocks = PlayerClass.rocks;
     public int iron = PlayerClass.iron;
 
 
     // Use this for initialization
     void Start () {
         showGUI = false;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnTriggerEnter(){
         showGUI = true;
     }
 
     void OnTriggerExit(){
         showGUI = false;
     }
 
     void RefineRocks(){
         if(clickedRock == true){
             for(int i = 0; i < rocks; i++){
                 rocks--;
                 iron++;
                 Debug.Log("Rocks: " + rocks + " Iron: " + iron);
             }
         }
     }
 
     void OnGUI(){
         if(showGUI == true){
             //This is the Background Box
             GUILayout.BeginArea(new Rect(500, 480, 600, 600), " ");
             GUILayout.Box("Factory", GUILayout.Width(600), GUILayout.Height(600));
             GUILayout.EndArea();
 
             //This is the buttons
             GUILayout.BeginArea(new Rect(500, 500, 600, 600), " ");
             GUILayout.BeginVertical();
             if(GUILayout.Button("Refine Snow", GUILayout.Width(200))){
                 if(PlayerClass.rocks >= 1){
                     clickedRock = true;
                 }
             }
             GUILayout.Space(10);
             if(GUILayout.Button("Refine Rocks", GUILayout.Width(200))){
                 //Stuff here
             }
             GUILayout.EndVertical();
             GUILayout.EndArea();
         }
     }
 }
 
               Thanks in advance!
Solved the issue. I just need to change the if(PlayerClass.rocks to rocks and the whole thing was fixed. 
Your answer
 
             Follow this Question
Related Questions
How to make my OnTriggerEnter() and Exit work 1 Answer
Script work in editor but not in build 0 Answers
Coin pickup script not working..? 1 Answer
play animation on keypress if in range 3 Answers