Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RuneyWolf · Jan 14, 2014 at 11:57 PM · c#guitrigger

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!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RuneyWolf · Jan 15, 2014 at 02:38 AM 0
Share

Solved the issue. I just need to change the if(PlayerClass.rocks to rocks and the whole thing was fixed.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

C# - Problem with trigger that won't activate 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges