I have a problem that involves 2 different scripts. What i am trying to achieve is to use Strings to access a static variable like the title suggest.
My First Script:
using UnityEngine;
using System.Collections;
public class GameInformation : MonoBehaviour
{
//Upgrades Info, 1 is bought while 0 is not bought
public static int TipJar;
}
My Second Script:
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.
}
}
}
My goal is to update the value in GameInformation.TipJar but it keeps containing 0.
I have tried to replace playerList[i].NewValue += 1; with GameInformation.playerList[i].Name(which is TipJar) += 1.
I have been searching for some time now and I could not find a solution, any ideas?