Error error CS0266: Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class itembuy : MonoBehaviour { public click click; public UnityEngine.UI.Text itemInfo; public float cost; public int count = 0; public int clickPower; public string itemName; private float _newCost;
void Update()
{
itemInfo.text = itemName + "\nCost :" + cost + "\nPower: +" + clickPower;
}
public void PurchasedUpgrade()
{
if (click.ki >= cost)
{
click.ki -= cost;
count += 1;
click.kiperclick += clickPower;
cost = Mathf.Round(cost * 1.15f);
_newCost = Mathf.Pow(cost, _newCost = cost);
}
}
}
idk whats wrong
click.ki must be an INT & cost is a float. You can't do what you're doing without converting between types. The easiest fix here is to probably make click a float. If not, you can convert types into what you need. Problem is, if you covert cost into an INT, i believe it gets rounded (can't remember if it's up or down) so you don't wind up with a decimal point. This could be fine, it may not be what you want. It just depends on what you're trying to do in the end.
Answer by UnityCoach · Jan 12, 2017 at 08:29 PM
One of your variables is an int and your trying to assign it a float value. You need to cast it to int first.
int myInt = 1;
float myFloat = 1.0f;
//myInt += myFloat // will throw an arror
myInt += (int) myFloat; // will work.
Answer by Eviljoako · Jan 13, 2017 at 03:04 PM
Im now sure what do u mean, do u have skype and there i can ask you?? Thanks :3
I have twitter @UnityCoach, a Facebook page and Facebook group
Your answer
Follow this Question
Related Questions
Errors With Game Over Script 1 Answer
PostProcessingFactory.cs 2 Answers
iTween NullReferenceException from GameObject Instantiation 0 Answers
Help! Values from previous Serialized List<> shows up again after a while using Coroutine 0 Answers
Unity Web Player Not Working and Solutions Not Working Either! 1 Answer