변수를 변경하는 버튼을 만들려고합니다. 따라서 새 버튼을 만들 때마다 새 코드를 작성하는 대신 저를 위해 할 수있는 함수를 만들었습니다.인수가 의도 한대로 작동하지 않습니다.
"void buttons"메서드에는 4 개의 인수가 있지만 "numberOF"인수가 작동하지 않습니다. 버튼을 클릭하면 "numberOf"와 "price"라는 변수가 변경되었지만 어떤 이유로 든 "numberOf"가 변경되지 않습니다.
나에게 도움이 될만한 사람이 여기 있습니다. 내가 사용하지 않은 것들이 많이 있다는 것을 압니다. 나는 이것을 처음 시도 할 때마다 긴 코드로 버튼을 만들었으므로 여전히 제거해야 할 관계없는 코드가 있습니다.
using UnityEngine;
using System.Collections;
public class Gui : MonoBehaviour
{
public int one;
//Money
public int money;
//Iventory
public int stone;
public int jord;
public int frø;
public int korn;
public int brød;
//Item price
public int stonePrice;
public int jordPrice;
public int frøPrice;
public int kornPrice;
public int brødPrice;
//Item inventory text and button text
private string moneyText;
private string stoneText;
private string jordText;
private string frøText;
private string kornText;
private string brødText;
private string stoneButton;
private string jordButton;
private string frøButton;
private string kornButton;
private string brødButton;
//Screen heith/width = 0
private int screenWidth;
private int screenHeight;
// Runs one time
void Start()
{
//Set variables to screen heith/width to 0
screenWidth = Screen.width - Screen.width;
screenHeight = Screen.height - Screen.height;
//Money reset
money = 10000;
//inventory reset
stone = 0;
jord = 0;
frø = 0;
korn = 0;
brød = 0;
//item price reset
stonePrice = 1;
jordPrice = 3;
frøPrice = 5;
kornPrice = 7;
brødPrice = 9;
//Set item text
moneyText = "money: " + money + " kr.";
stoneText = " stone " + stone;
jordText = " jord " + jord;
frøText = " frø " + frø;
kornText = " korn " + korn;
brødText = " brød " + brød;
//set button text
stoneButton = "Stone " + stonePrice + " kr.";
jordButton = "Jord " + jordPrice + " kr.";
frøButton = "Frø " + frøPrice + " kr.";
kornButton = "Korn " + kornPrice + " kr.";
brødButton = "Brød " + brødPrice + " kr.";
}
void Update()
{
stone = stone;
jord = jord;
frø = frø;
korn = korn;
brød = brød;
moneyText = moneyText;
stoneText = stoneText;
jordText = jordText;
frøText = frøText;
kornText = kornText;
brødText = brødText;
//Check item text changes
moneyText = "money: " + money + " kr.";
stoneText = " stone " + stone;
jordText = " jord " + jord;
frøText = " frø " + frø;
kornText = " korn " + korn;
brødText = " brød " + brød;
//Check button text changes
stoneButton = "Stone " +stonePrice + " kr.";
jordButton = "Jord " + jordPrice + " kr.";
frøButton = "Frø " + frøPrice + " kr.";
kornButton = "Korn " + kornPrice + " kr.";
brødButton = "Brød " + brødPrice + " kr.";
}
void OnGUI()
{
buttons(150, stoneButton, stone, stonePrice);
if (GUI.Button (new Rect (Screen.width - 100, Screen.height - 20, 100, 20), "End Turn"))
{
newRound();
}
//Iventory
GUI.TextArea (new Rect (screenWidth + 1, screenHeight + 2, Screen.width, 20),moneyText + " Inventory: " + stoneText + jordText + frøText + kornText + brødText);
}
void make_buttons(int position_heigth, string buttonText, int numberOF, int price)
{
GUI.TextArea (new Rect (screenWidth + 2, screenHeight + position_heigth + 80, 80, 20), buttonText);
if (GUI.Button (new Rect (screenWidth + 80, screenHeight + position_heigth + 80, 40, 20), "Buy"))
{
if (money > price)
{
numberOF = 1 + numberOF;
money = money - price;
}
else if (money == price)
{
numberOF = 1 + numberOF;
money = money - price;
}
}
if (GUI.Button (new Rect (screenWidth + 120, screenHeight + position_heigth + 80, 40, 20), "Sell"))
{
if (numberOF > 0)
{
numberOF = numberOF - 1;
money = money + price;
}
}
}
void newRound()
{
stonePrice = stonePrice * 2;
jordPrice = jordPrice * 2;
frøPrice = frøPrice * 2;
kornPrice = kornPrice * 2;
brødPrice = brødPrice * 2;
}
}
여기에 질문이 없습니다. 도움에 대한 광범위한 요청. 너 뭐가 붙어 있니? – techvice
"사용하지 않는 것들이 많이 있습니다."- 관련성 높은 부분 만 표시하도록 코드를 수정하십시오. "참조로 전달"을 읽을 필요가 있을지 모르지만 다음과 같이 말하기는 어렵습니다. 당신이 게시 한 코드 벽에 정말 문제가됩니다. –
** 여자 친구 오류 405 : 의도적으로 작동하지 않는 인수 ** : D – LearnCocos2D