私は2つの異なるスクリプトを含む問題があります。私が達成しようとしているのは、タイトルのように静的変数にアクセスするためにStringを使用することです。静的変数で文字列を使用しますか?
私の最初のスクリプト:
using UnityEngine;
using System.Collections;
public class GameInformation : MonoBehaviour
{
//Upgrades Info, 1 is bought while 0 is not bought
public static int TipJar;
}
は私の2番目のスクリプト:
using UnityEngine;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
public class Upgrades : MonoBehaviour
{
public List<PlayerTank> playerList;
public class PlayerTank // Here is my class for PlayerTank
{
public string Name;
public string Value;
// This is a constructor to make an instance of my class.
public PlayerTank (string NewName, int NewValue)
{
Name = NewName;
Value = NewValue;
}
}
void Start()
{
playerList = new List<PlayerTank>();
playerList.Add (new PlayerTank("TipJar", GameInformation.TipJar));
//To loop all the list
for(int i = 0; i < playerList.Count; i++)
{
int TempInt = i;
playerList[i].NewValue += 1; //This line works but Gameinformation.TipJar will still contain the value 0, i want it to be 1.
}
}
}
私の目標は、GameInformation.TipJar
に値を更新することですが、それは0
を含む保持します。
私はGameInformation.playerList[i].Name(which is TipJar) += 1
とplayerList[i].NewValue += 1;
を交換しようとしています。
私は今、いくつかの時間を探していると私は解決策、任意のアイデアを見つけることができませんでしたか?
この質問はあまり明確ではありませんが、達成しようとしているのは何ですか?あなたは期待される成果を得ていますか? – Bassie
申し訳ありませんが、何を達成しようとしていますか?非常に不明です – Tinwor
あなたのGameInformationクラスはint var "TipJar"しか定義していません – joreldraw