Unity:错误 CS0246:找不到类型或命名空间名称 'image'(是否缺少 using 指令或程序集引用?)”
Unity: error CS0246: The type or namespace name 'image' could not be found (are you missing a using directive or an assembly reference?)"
我试图制作一个弹药计数系统,其中的子弹图像会随着角色发射子弹而消失。我正在关注 this tutorial:
看起来没问题,但现在我得到这个错误:
"Assets \ Scripts \ GameFlow.cs (72,28): error CS0246: The type or
namespace name 'image' could not be found (are you missing a directive
or an assembly reference?)"
我看不出问题所在。我以为我会通过输入“using UnityEngine.UI;
”来解决,但问题仍然存在。任何人都知道我该如何解决它?谢谢。
脚本中的代码是:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameFlow : MonoBehaviour
{
public static float remainingShots = 6;
public Transform shot1;
public Transform shot2;
public Transform shot3;
public Transform shot4;
public Transform shot5;
public Transform shot6;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (remainingShots > 0)
{
shot1.GetComponent<image> ().enabled = true;
}
else
{
shot1.GetComponent<image> ().enabled = false;
}
if (remainingShots > 1)
{
shot2.GetComponent<image> ().enabled = true;
}
else
{
shot2.GetComponent<image> ().enabled = false;
}
if (remainingShots > 2)
{
shot3.GetComponent<image> ().enabled = true;
}
else
{
shot3.GetComponent<image> ().enabled = false;
}
if (remainingShots > 3)
{
shot4.GetComponent<image> ().enabled = true;
}
else
{
shot4.GetComponent<image> ().enabled = false;
}
if (remainingShots > 4)
{
shot5.GetComponent<image> ().enabled = true;
}
else
{
shot5.GetComponent<image> ().enabled = false;
}
if (remainingShots > 5)
{
shot6.GetComponent<image> ().enabled = true;
}
else
{
shot6.GetComponent<image> ().enabled = false;
}
if(Input.GetButtonDown("Fire1"))
{
remainingShots -= 1;
}
}
}
"Assets \ Scripts \ GameFlow.cs (72,28): error CS0246: The type or
namespace name 'image' could not be found (are you missing a directive
or an assembly reference?)"
将所有 'image' 类型更改为 'Image'。
我试图制作一个弹药计数系统,其中的子弹图像会随着角色发射子弹而消失。我正在关注 this tutorial:
看起来没问题,但现在我得到这个错误:
"Assets \ Scripts \ GameFlow.cs (72,28): error CS0246: The type or namespace name 'image' could not be found (are you missing a directive or an assembly reference?)"
我看不出问题所在。我以为我会通过输入“using UnityEngine.UI;
”来解决,但问题仍然存在。任何人都知道我该如何解决它?谢谢。
脚本中的代码是:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameFlow : MonoBehaviour
{
public static float remainingShots = 6;
public Transform shot1;
public Transform shot2;
public Transform shot3;
public Transform shot4;
public Transform shot5;
public Transform shot6;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (remainingShots > 0)
{
shot1.GetComponent<image> ().enabled = true;
}
else
{
shot1.GetComponent<image> ().enabled = false;
}
if (remainingShots > 1)
{
shot2.GetComponent<image> ().enabled = true;
}
else
{
shot2.GetComponent<image> ().enabled = false;
}
if (remainingShots > 2)
{
shot3.GetComponent<image> ().enabled = true;
}
else
{
shot3.GetComponent<image> ().enabled = false;
}
if (remainingShots > 3)
{
shot4.GetComponent<image> ().enabled = true;
}
else
{
shot4.GetComponent<image> ().enabled = false;
}
if (remainingShots > 4)
{
shot5.GetComponent<image> ().enabled = true;
}
else
{
shot5.GetComponent<image> ().enabled = false;
}
if (remainingShots > 5)
{
shot6.GetComponent<image> ().enabled = true;
}
else
{
shot6.GetComponent<image> ().enabled = false;
}
if(Input.GetButtonDown("Fire1"))
{
remainingShots -= 1;
}
}
}
"Assets \ Scripts \ GameFlow.cs (72,28): error CS0246: The type or namespace name 'image' could not be found (are you missing a directive or an assembly reference?)"
将所有 'image' 类型更改为 'Image'。