What do i have to do about this?,
using System.Collections.Generic;
public class Click : MonoBehaviour {
public object Instance;
public UnityEngine.UI.Text BPC;
public UnityEngine.UI.Text BoxesDisplay;
public float Boxes = 0f;
public int Boxesperclick = 1;
public object CurrencyConverter { get; private set; }
void Update ()
{
BoxesDisplay.text = "Boxes: " + CurrencyConverter.Instance.GetCurrencyIntoString(Boxes, false, false);
BPC.text = CurrencyConverter.Instance.GetCurrencyIntoString(Boxesperclick, false, true) + "Boxes/Click";
}
public void Clicked()
{
Boxes += Boxesperclick;
}
}
,
Downvote because:
No question has been asked / no problem has been described.
Code is not formatted as code. See the site navigation guide if you have problems with using UnityAnswers.
This is a trivial debugging question and does belong to the Help Room, not the default space.
You posted additional information as answer and accepted this "answer" which basically marks this question as solved even nothing got solved at all.
Answer by Vilogrec · Nov 25, 2017 at 02:51 PM
Instance is not working, it says object does not contain a defination
This is connected with this:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CurrencyConverter : MonoBehaviour { private static CurrencyConverter instance; public static CurrencyConverter Instance { get {
return instance;
}
}
void awake()
{
CreateIntance();
}
void CreateIntance()
{
if (instance == null)
{
instance = this;
}
}
public string GetCurrencyIntoString(float valueToConvert, bool currencyPerSec, bool currencyPerClick)
{
string converted;
if (valueToConvert >= 1000000)
{
converted = (valueToConvert / 1000000f).ToString("F3") + " M";
}
else if (valueToConvert >= 1000)
{
converted = (valueToConvert / 1000f).ToString("F3") + " K";
}
else
{
converted = "" + valueToConvert;
}
if (currencyPerSec == true)
{
converted = converted + " BPS ";
}
if (currencyPerClick == true)
{
converted = converted + " BPC";
}
return converted;
}
}
Elbekri: I'm not sure if it will "unlock" you @vilogrec but i see that you create a method called "awake" ins$$anonymous$$d of "Awake" and also you named your class "CurrencyConverter" but you also declared an auto-property of type "object" which you also named "CurrencyConverter"
Answer by Bunny83 · Nov 25, 2017 at 06:10 PM
You're doing a lot of strange things here. First of all your main problem (which you stated in your "answer") is that you named your class "CurrencyConverter" but you also declared an auto-property of type "object" which you also named "CurrencyConverter". So inside your "Click" class "CurrencyConverter" refers to your property and not to your CurrencyConverter class. It's not really clear what this property is good for so you may want to just remove it.
The next problem is in your CurrencyConverter class you create a method called "awake". However this will never be called by Unity as the method has to be named "Awake" (case matters).
Another misleading / misnamed method is "CreateInstance". It does not create anything. It just assignes / initializes the static instance variable to this instance. So this method name should be refactored and given a proper name.
Finally i don't see any reason why your CurrencyConverter class should be a MonoBehaviour and moreover why it actually should be a singleton. The only useful method "GetCurrencyIntoString" is actually a pure function so it can / should be simply a static method.
Your answer
Follow this Question
Related Questions
Can you change fillAmount to a float value? 0 Answers
Idle Clicker Incremental Cost 1 Answer
Idle Time Camera Switch 1 Answer
Managing taking damage. 1 Answer