Adding Int's from different and the same script
After looking for half an hour it seems like there is no simple explanation for what I've been doing wrong. I'm trying to make a purchasing system but it keeps saying I can't use + or -. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Purchasing : MonoBehaviour {
public int Money = 500;
Inventory Inventory = Inventory.GetComponent<Inventory>();
public void Marine(){
Money = Money - 100;
Debug.Log ("-100 Money");
Inventory.Marine = Marine + 1;
Debug.Log("+1 Marine.");
if (Money < 0) {
Money = Money + 100;
Debug.Log ("Not Enough Money!");
Inventory.Marine = Marine - 1;
Debug.Log ("Marine RESINDED.");
}
}
public void Assault_Rifle(){
Money = Money - 100;
Debug.Log ("-100 Money");
Inventory.Assault_Rifle.Add(1);
Debug.Log ("+1 Assault Rifle");
if(Money < 0) {
Money + 100;
Debug.Log("Not Enough Money!");
Inventory.Assault_Rifle = Assault_Rifle - 1;
Debug.Log ("Assault Rifle RESINDED.");
}
}
That is the first script the main one the second one is here. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Inventory : MonoBehaviour {
public float Pistol = 0;
public float Assault_Rifle = 0;
public float Marine = 0;
void Start () {
}
// Update is called once per frame
void Update () {
}
At the end I changed it to a float thinking it might work better using floats.
Answer by SkullMaster259 · Jul 04, 2017 at 01:13 PM
I've got the main integer problem fixed but now I'm working with
public int Money = 500;
GameObject inventory = GameObject.Find("Inventory");
Inventory Inventory = inventory.GetComponent<Inventory>();
public void Marine(){
Money = Money - 100;
Debug.Log ("-100 Money");
Inventory.Marine += 1;
Debug.Log("+1 Marine.");
if (Money < 0) {
Money = Money + 100;
Debug.Log ("Not Enough Money!");
Inventory.Marine -= 1;
Debug.Log ("Marine RESINDED.");
}
}
public void Assault_Rifle(){
Money = Money -= 100;
Debug.Log ("-100 Money");
Inventory.Assault_Rifle +=1;
Debug.Log ("+1 Assault Rifle");
if(Money < 0) {
Money += 100;
Debug.Log("Not Enough Money!");
Inventory.Assault_Rifle -=1;
Debug.Log ("Assault Rifle RESINDED.");
}
}
// Update is called once per frame
void Update () {
}
}
line 3-5 being the main problem.
Your answer
Follow this Question
Related Questions
Adding a int and a float? 2 Answers
Help with float and int,Help with float and integer 0 Answers
Optimization Question - Floats or Ints? 0 Answers
Color float rgb values cannot be converted correctly to int, and hex. 1 Answer
Int not getting rounded data 0 Answers