- Home /
Question by
Haeder2132 · Sep 12, 2017 at 04:09 PM ·
c#errorbugcall
how i -10 from thing in another code
i need to -10 from thing in another code like a that
using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using UnityEngine;
public class Buy_H : MonoBehaviour {
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void BackToGame()
{
SceneManager.LoadScene("Main");
}
public void BUY_H()
{
if (DataManegement.datamanegement.AllCrystals < 20)
{
Debug.Log("ﺔﻴﻓﺎﻛ ﺮﻫﺍﻮﺟ ﻚﻳﺪﻟ ﺲﻴﻟ");
}
if (DataManegement.datamanegement.AllCrystals > 20)
{
DataManegement.datamanegement.AllCrystals - 10;
}
}
}
the another code *
using System.Collections; using System.Collections.Generic; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using UnityEngine;
public class DataManegement : MonoBehaviour {
public static DataManegement datamanegement;
//my variables
public int tokensHighScore;
public int TotalTokensCollcted;
public int AllCrystals;
void Awake()
{
Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
datamanegement = this;
DontDestroyOnLoad (gameObject);
}
public void SaveData()
{
BinaryFormatter binFrom = new BinaryFormatter();
FileStream file = File.Create(Application.persistentDataPath + "gameInfo.dat");
gameData data = new gameData();
data.tokensHighScore = tokensHighScore;
data.TotalTokensCollcted = TotalTokensCollcted;
data.AllCrystals = AllCrystals;
binFrom.Serialize(file, data);
file.Close();
}
public void LoadData()
{
if (File.Exists(Application.persistentDataPath + "gameInfo.dat"))
{
BinaryFormatter binForm = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "gameInfo.dat", FileMode.Open);
gameData data = (gameData)binForm.Deserialize(file);
file.Close();
tokensHighScore = data.tokensHighScore;
TotalTokensCollcted = data.TotalTokensCollcted;
AllCrystals = data.AllCrystals;
}
}
} [Serializable] class gameData { public int tokensHighScore; public int TotalTokensCollcted; public int AllCrystals; }
Comment
Best Answer
Answer by MT369MT · Sep 12, 2017 at 04:28 PM
Hi I think you did wrong the subtraction. Write this: AllCrystals -= 10 Or: AllCrystals = AllCrystals - 10