- Home /
Need help with my "simple" crafting system
This is my code
using UnityEngine;
using System.Collections;
public class Craft : MonoBehaviour {
public int wood = 0;
public int metal = 0;
public int iron = 0;
public int ShortSword = 0;
public int LongSword = 0;
public bool craftStart = false;
public float Timer = 0;
public bool craftReady = false;
void OnGUI(){
if (GUILayout.Button("Craft Short Sword")){
shortSword();
}
}
void shortSword()
{
craftStart = true;
if(wood >= 5 && metal >= 5)
{
if(craftReady == true){
wood -= 5;
metal -= 5;
ShortSword += 1;
Debug.Log ("You've successfuly crafting a Short Sword!");
}
}else{
Debug.Log ("Not Enough Resources.");
}
}
// Update is called once per frame
void Update () {
if(craftStart == true){
Timer += 1;
if(Timer == 50){
craftStart = false;
craftReady = true;
}
}
}
}
When I press the "Craft Short Sword" button it start the Timer and when the Timer = 50 it change the "craftReady = false" to True and when the "craftReady" equals True it's supposed to do
if(craftReady == true){
wood -= 5;
metal -= 5;
ShortSword += 1;
Debug.Log ("You've successfuly crafting a Short Sword!");
}
but it does nothing... How do I fix this?
Comment
Best Answer
Answer by getyour411 · Jan 19, 2014 at 09:23 PM
When shortSword() is called from Button click, you have
if(craftReady == true){
but at this point craftReady is false.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130901im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Stop from showing point value 1 Answer
Distribute terrain in zones 3 Answers
Creating a timer for combat (C#) 1 Answer
Particle memory overhead 1 Answer