- Home /
Question by
zak666 · Jun 03, 2015 at 01:10 PM ·
scriptingbasics
he type or namespace name `Image' could not be found
Hi Gang, Attempting to create a Health bar Code In C# with the new Health / progress bar however it cannot find image.
using UnityEngine;
using System.Collections;
public class HealthBar : MonoBehaviour {
float Health =0f;
// Update is called once per frame
void Update () {
Image image = GetComponent<Image>();
image.fillAmount = .2f;
}
}
Comment
Answer by Landern · Jun 03, 2015 at 01:12 PM
You need to add the namespace UnityEngine.UI to the top of the of your script, this is the namespace that the type Image exists in.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
// etc etc.
Alternatively you can fully qualify the namespace and not use the using statement.
Example in your Update method.
UnityEngine.UI.Image image = GetComponent<UnityEngine.UI.Image>();