Hi
I’m using Player Prefs to set two of my variables. I took the code from the Unity Scripting API. While I’m able to set my variable to a specific number using the PlayerPrefs.SetInt function I can’t add two variables.
My code is
using UnityEngine;
using System.Collections;
public class League : MonoBehaviour {
int DivisionNumber;
int RacesLeft;
int Points;
int PointsForWin;
int PointsForPrize;
int PointsForOut;
int MoneyForWin;
int MoneyForPrize;
int MoneyForOut;
int FameForWin;
int FameForPrize;
int FameForOut;
Career_Variables career = GameObject.Find("career_Variables").GetComponent<Career_Variables>();
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (RacesLeft >= 0 && Points >= PointsForWin)
{
DivisionNumber --;
PlayerPrefs.SetInt("Career_Variables.Fame", Career_Variables.Fame + FameForWin);
PlayerPrefs.SetInt("Career_Variables.Money", Career_Variables.Money + FameForWin);
}
}
}
This is all I got to in my code before it started generating errors. It shows the errors "error CS1503: Argument #2' cannot convert
object’ expression to type int'" error CS1502: The best overloaded method match for
UnityEngine.PlayerPrefs.SetInt(string, int)’ has some invalid arguments and error CS1503: Argument #2' cannot convert
object’ expression to type `int’.
However when I change it from Career_Variables.Money + MoneyForWin/Career_Variables.Fame + FameForWin those 3 errors go away. This leads me to wonder if you can add two variables with the Player Prefs because I copied and pasted the GetComponent part of the code from another file which showed no error and the gameobject name was the same.
Any help will be appreciated
Thank you in advance