This is my first time using Unity and Im slowly learning the ropes. I’ve been making a puzzle escape room game, and I wish to update a hotbar slot (A raw image) upon clicking on an object. It should remove the object, then set the first hotbar image to an image of the object. I believe I have incorrectly located which raw image I wish to edit, and was wondering how i find a path to that image. The Raw Image i wish to edit is under my Main Camera, currently named “Image”
I Know when locating a Game Object, you can use the string of code:
Object = GameObject.FindGameObjectWithTag(“ObjectName”);
Is there a similar code format to find a Raw Image?
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public class Interact : MonoBehaviour
{
private RawImage Image1;
private Camera Camera;
private Texture Image1T;
private void Awake()
{
Camera = Camera.main;
Image1 = Camera.GetComponent<RawImage>();
}
private void OnMouseDown()
{
gameObject.SetActive(false);
Image1T = (Texture)AssetDatabase.LoadAssetAtPath("Assets/Textures/Ball.jpg", typeof(Texture));
Image1.texture = Image1T;
}
}