Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 统一:类型或名称空间名称';功能';找不到_C#_Unity3d - Fatal编程技术网

C# 统一:类型或名称空间名称';功能';找不到

C# 统一:类型或名称空间名称';功能';找不到,c#,unity3d,C#,Unity3d,我正在制作一个3D Unity游戏,我想实现一个计时器。问题是我在scirpt中收到以下错误: 无法将类型“float”隐式转换为“int”。明确的 存在转换(您是否缺少演员阵容?) 如何解决这个问题 脚本计时器。cs: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Timer : MonoBehaviour {

我正在制作一个3D Unity游戏,我想实现一个计时器。问题是我在scirpt中收到以下错误:

无法将类型“float”隐式转换为“int”。明确的 存在转换(您是否缺少演员阵容?)

如何解决这个问题

脚本计时器。cs:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Timer : MonoBehaviour
{
    Text instruction;
    // Start is called before the first frame update
    void Start()
    {
        instruction = GetComponent<Text>();

    }

    // Update is called once per frame
    int timeLeft = 30;

    void Update()
    {
        timeLeft -= Time.deltaTime;
        instruction.text= (timeLeft).ToString();
        if (timeLeft < 0)
        {
         //   GameOver();
        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
公共类计时器:单行为
{
文本教学;
//在第一帧更新之前调用Start
void Start()
{
指令=GetComponent();
}
//每帧调用一次更新
int timeLeft=30;
无效更新()
{
timeLeft-=Time.deltaTime;
指令.text=(timeLeft.ToString();
如果(时间间隔<0)
{
//GameOver();
}
}
}
此外,在inspector中,我似乎无法指定特定的文本字段


时间。deltaTime
是一个浮点数,您试图在
timeLeft-=Time中为一个整数分配一个浮点数。deltaTime
timeLeft
更改为
float

时间。deltaTime
是一个浮点数

timeLeft
更改为浮动

float timeLeft=30f;
或者按照它的预期:
timeLeft-=(int)Time.deltaTime

此处:

int timeLeft = 30;
timeLeft -= Time.deltaTime;

Time.deltaTime
是一个
float
timeLeft
int
,在执行其余操作之前,需要将float转换为int

int timeLeft = 30;
timeLeft -= (int)Time.deltaTime;
这就是错误的意思

存在显式转换(是否缺少强制转换?)


对!

你是从哪里得到这个错误的?你应该首先问谷歌这个错误是什么意思。