我试着让一些文字显示一个价格,在每次你按下一个按钮时,价格都会改变5倍。对不起,如果我对堆栈和编码做了错误的解释。问问我你是否需要更多的背景。这是使用代码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);
}
}
}发布于 2022-06-24 13:31:56
Click.clicks = Click.clicks - ClickerPrice;在这里,您试图将浮点值转换为整数字段,并且没有对其进行隐式转换,因此需要在某个地方强制转换(int)以不加限制地转换值:
Clicks.clicks = Click.clicks - (int)ClickerPrice;或
Click.clicks = (int)(Click.clicks - ClickerPrice);https://stackoverflow.com/questions/72742999
复制相似问题