Joshua
Joshua

Reputation: 503

How to: Get a reference to a UI Image

Similar to a previous question I asked, I am now looking to learn how to get a reference for my image TestImage in a script.

So far I've tried this:

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

public class imageGrab : MonoBehaviour
{

        [Space] public RawImage testImage;

         Texture2D profileTexture;




    // Start is called before the first frame update
    void Start()
    {
        profileTexture = new Texture2D(2, 2);
    }

    void Awake() 
    {
        PlayPortalProfileClient.Instance.GetMyProfilePicture((error, data) =>
            {
                if (error != null)
                {
                    ErrorLogging("Error requesting my profile picture.", error);
                }
                else
                {
                    Debug.Log("Got my profile picture successfully.");

                    profileTexture.LoadImage(data);
                    testImage.texture = profileTexture;
                }
            });
    }

    // Update is called once per frame
    void Update()
    {

    }
}

But run into this error, Assets/imageGrab.cs(8,24): error CS0246: The type or namespace name 'RawImage' could not be found (are you missing a using directive or an assembly reference?)

What could I do differently to correctly get the reference? Is there something as simple as referencing a text element? Thanks!

Upvotes: 1

Views: 529

Answers (1)

Ahmed Ali
Ahmed Ali

Reputation: 1964

Put this at top:

using UnityEngine.UI

Upvotes: 2

Related Questions