Help with UI Thing

Hello guyz,
I was learning making games as Adam told me to go to www.unity3d.com/learn.
The problem is that in the survival shooter tutorial ,there is a script named “PlayerHealth” i thought to check it
but i get this error,
Assets/Scripts/PlayerHealth.cs(2,19): error CS0138: `UnityEngine.UI’ is a type not a namespace. A using namespace directive can only be applied to namespaces

Help,Code is

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

public class PlayerHealth : MonoBehaviour
{
    public int startingHealth = 100;                            // The amount of health the player starts the game with.
    public int currentHealth;                                   // The current health the player has.
    public Slider healthSlider;                                 // Reference to the UI's health bar.
    public Image damageImage;                                   // Reference to an image to flash on the screen on being hurt.
    public AudioClip deathClip;                                 // The audio clip to play when the player dies.
    public float flashSpeed = 5f;                               // The speed the damageImage will fade at.
    public Color flashColour = new Color(1f, 0f, 0f, 0.1f);     // The colour the damageImage is set to, to flash.


    Animator anim;                                              // Reference to the Animator component.
    AudioSource playerAudio;                                    // Reference to the AudioSource component.
    PlayerMovement playerMovement;                              // Reference to the player's movement.
    PlayerShooting playerShooting;                              // Reference to the PlayerShooting script.
    bool isDead;                                                // Whether the player is dead.
    bool damaged;                                               // True when the player gets damaged.


    void Awake ()
    {
        // Setting up the references.
        anim = GetComponent <Animator> ();
        playerAudio = GetComponent <AudioSource> ();
        playerMovement = GetComponent <PlayerMovement> ();
        playerShooting = GetComponentInChildren <PlayerShooting> ();

        // Set the initial health of the player.
        currentHealth = startingHealth;
    }


    void Update ()
    {
        // If the player has just been damaged...
        if(damaged)
        {
            // ... set the colour of the damageImage to the flash colour.
            damageImage.color = flashColour;
        }
        // Otherwise...
        else
        {
            // ... transition the colour back to clear.
            damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
        }

        // Reset the damaged flag.
        damaged = false;
    }


    public void TakeDamage (int amount)
    {
        // Set the damaged flag so the screen will flash.
        damaged = true;

        // Reduce the current health by the damage amount.
        currentHealth -= amount;

        // Set the health bar's value to the current health.
        healthSlider.value = currentHealth;

        // Play the hurt sound effect.
        playerAudio.Play ();

        // If the player has lost all it's health and the death flag hasn't been set yet...
        if(currentHealth <= 0 && !isDead)
        {
            // ... it should die.
            Death ();
        }
    }


    void Death ()
    {
        // Set the death flag so this function won't be called again.
        isDead = true;

        // Turn off any remaining shooting effects.
        playerShooting.DisableEffects ();

        // Tell the animator that the player is dead.
        anim.SetTrigger ("Die");

        // Set the audiosource to play the death clip and play it (this will stop the hurt sound from playing).
        playerAudio.clip = deathClip;
        playerAudio.Play ();

        // Turn off the movement and shooting scripts.
        playerMovement.enabled = false;
        playerShooting.enabled = false;
    }     
}

Please Note That Im using Unity 4 it dosent have UI option,Help me to fix the error please.

Remove line 4?

Dont you think it will ruin the work of the script?

I have not gotten far into Unitys UI. I still use EZGUI. Tho, I think I tried it briefly once,and do not recall it requiring a using…

That being said, erase it. See what happens. There is always an undo button.

What version of unity are you using? Could you be using an old or obsolete version? UnityEngine.UI has been included since 4.6, which implies you are using. 4.5 or earlier.

1 Like

Yes, you do need it.

I’m using Unity 4,how can fix that error please :frowning:

Unity … 4… What? 4.1? 4.2? 4.3? 4.4? 4.5? 4.6?

Please read my post above.

You must upgrade to Unity 4.6 or later to use the UI tools.

Otherwise you have to use legacy GUI or a third party tool.

:frowning:

Can i have a download link of Unity 4?

Its clearly marked on the site, if you grab 4.6 you should be able to upgrade your project with out breaking anything.

Why not just do this in 5.0?

1 Like

I did Adam,But when it’s installing it took whole day,And i quit the installation

A whole day? Then there’s something wrong somewhere… Unity5 is under 5gb all in. Unity 4 is only a few mb smaller and is more like 4.5gb. I can install on a machine from 2008 in minutes. Can you tell me more about your setup? You will need either the latest 4.6 or 5.0. Both are about the same size… so you’ll have to install one of them to get the new UI. I’d suggest Unity 5.

I downloaded Unity5 installer,When it downloads it’s file it too kwhole day

Very slow connection? Well, once you have the data, the install should he fast. Either way, you’ll need an up to date copy of unity, either 4 or 5.

How can i get the Copy?

As always, start with our site:

The download page is here: