[英]error CS0266: Cannot implicitly convert type 'float' to 'int'. An explicit conversion exists (are you missing a cast?)
Im trying to make some text display a price that changes by 5 present every time you press a button.我试图让一些文本显示一个价格,每次按下按钮时,价格都会改变 5。 Sorry if i explain badly im new to stack and coding.
抱歉,如果我对堆栈和编码新手解释得很糟糕。 Just ask me if you need more context.
只要问我您是否需要更多上下文。 This is unity using visual studio code c#.
这是使用 Visual Studio 代码 c# 的统一。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class clicksUpPerSec : MonoBehaviour
{
public Button addBut1PS;
public GameObject ShowClickerPrice;
public static int perSec = 0;
public static float ClickerPrice = 10f;
public float Prosent = 5f;
void Start()
{
Button btn = addBut1PS.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void Update() {
ShowClickerPrice.GetComponent<Text>().text = "COST: " + ClickerPrice;
}
void TaskOnClick(){
if(Click.clicks >= ClickerPrice) {
perSec = perSec + 1;
Click.clicks = Click.clicks - ClickerPrice;
ClickerPrice = (((Prosent * ClickerPrice) / 100f) + ClickerPrice);
}
}
}
Click.clicks = Click.clicks - ClickerPrice;
Here you are trying to assing float value to an integer field and there is no implicit conversion for that, you need to cast (int) somewhere to convert value expilictly:在这里,您尝试将浮点值分配给整数字段,并且没有隐式转换,您需要在某处强制转换 (int) 以显式转换值:
Clicks.clicks = Click.clicks - (int)ClickerPrice;
or或者
Click.clicks = (int)(Click.clicks - ClickerPrice);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.