【问题标题】:Simple clicker in unity and error that i can't understand C#统一的简单点击器和我无法理解 C# 的错误
【发布时间】:2016-12-24 22:18:30
【问题描述】:

我正在尝试在 Unity 中制作简单的点击器。我正在使用互联网教程,我尝试自己做一些事情。我想做的只是将一件事从浮动更改为长,因为我想尽我所能进行最大的“点击”。 错误:'ping.toInt64(float)' 必须有正文,因为它没有标记为抽象、外部或部分

代码:

    using UnityEngine;
    using System.Collections;
    using System;

    public class ping : MonoBehaviour {

    public UnityEngine.UI.Text gpc;
    public UnityEngine.UI.Text GoldDisplay;
    /*public long gold = 0.00f;*/

    public static long toInt64(
    float gold = 0.00f
    );
    public int goldperclick = 1; 

    void Update(){
     GoldDisplay.text = "Ping: " + gold;
     gpc.text = goldperclick + "ping/click";
 }

     public void Clicked(){
     gold += goldperclick;
}

}

【问题讨论】:

  • 你必须为toInt64提供code,就像这里的其他方法一样。

标签: c# unity3d


【解决方案1】:

你声明了一个方法,toInt64,但没有实现它。查看该方法与您的 Update 方法之间的区别。 (你想用toInt64 完成什么?)

public static long toInt64()
{
    return Convert.ToInt64(gold);
}

当然,您必须在上面的行中取消注释您对gold 的定义。

【讨论】:

  • 我在微软网站上找到了它,我认为它应该可以工作。我不知道如何正确地将其转换为 long。
  • 非常感谢。我如何在其他文件中使用黄金?我的意思是我有 ping.cs(你可以在这里看到)itemmanager.cs,我在其中使用 ping.gold,现在它很糟糕,但在更改之前它可以工作。
  • 听起来您想在 ping 类之外访问 ping.gold,对吗?如果是这样,您可以随时将gold 更改为public long gold { get; private set; } 的属性。
  • 如果不是问题,我可以问你别的吗?我有一个新错误:goldpersec.cs(20,25) 无法将类型“long”隐式转换为“int”。存在显式转换(您是否缺少演员表?)
  • 这里是一段代码 public int GetGoldPerSec(){ int tick = 0; foreach (ItemManager item in items) { tick += item.count * item.tickValue; } 返回刻度; } public void AutoGoldPerSec(){ ping.gold += GetGoldPerSec (); }
【解决方案2】:

改变这个:

public static long toInt64(
float gold = 0.00f
);

到这里:

float gold;
public static long toInt64(){
    gold = 0.00f;
}

我只是在更正您的格式。我不知道你想实现什么逻辑。祝你好运

【讨论】:

  • 谢谢。我什至不知道 C#,这就是为什么它看起来很诡异。
  • @Bajor 如果此解决方案已回答您的问题,请阅读this
猜你喜欢
  • 2023-03-13
  • 2015-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多