Search Unity

Error CS0029 Need Help !!

Discussion in 'Scripting' started by Zeko_Aliraqi2012, Sep 24, 2014.

  1. Zeko_Aliraqi2012

    Zeko_Aliraqi2012

    Joined:
    Sep 24, 2014
    Posts:
    2
    i'm have problem with this script i don't know why he's giving me error !!
    Here is th script :
    using UnityEngine;
    using System.Collections;

    public class HitMarkControl : MonoBehaviour {

    private GUITexture HitMark;

    void Start ()
    {
    HitMark = GetComponents<GUITexture> ();
    }

    void Update ()
    {
    if (Input.GetButton ("Fire2")) {
    HitMark.enabled = true;
    } else {
    HitMark.enabled = false;
    }
    }
    }

    And the error is :
    Assets/Scripts/HitMarkControl.cs(10,17): error CS0029: Cannot implicitly convert type `UnityEngine.GUITexture[]' to `UnityEngine.GUITexture'

    Help if u know any thing !
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    You're calling GetComponents, which returns an array of (in this case) GUITextures, and trying to stuff this into a simple GUITexture variable.