#UI Image Enable

1 messages · Page 1 of 1 (latest)

humble pike
#

Can you make it appear in Editor mode?

#

great bug, discord, I'll just retype my message

#

Can you make the image appear while in Editor mode?

If you can flip switches and move things around to make it look like you want,
then code can achieve the same thing.

jade arch
#

ok i didn't see this gimme a second to read

#

what do you mean

#

it does not appear in editor mode no

#

oh

#

ok lemme see

#

idk how to do that

humble pike
#

hey, was afk a bit, sec

jade arch
#

i think i found the gui but it's a white box that i can't move

humble pike
#

Perhaps you didn't go about making a UI the proper way.
I suggest finding a short UI tutorial on youtube.

You can reference the image in the monobehaviour script, as you're doing now.
But the UI game object which is going to display the image, needs to be the child of a Canvas, which also means it will have a RectTransform instead of a Transform.

It is most practical that those objects are separate. But what kind of object is your script attached to?

jade arch
#

i made ui before, but now i want the image to appear over the whole screen

#

i watched a tutorial and did exactly as they did and it didn't work because i already had a trigger i guess

#

idk what kind of object

#

it's a box trigger

#

does it matter if the trigger is invisible?

humble pike
#

colliders don't need to be visible in Play mode

#

I have an idea

#

Create a dedicated script for the UI object

#

Or wait, what do you want to achieve in full here?

jade arch
#

collide with object, sound plays, image shows as sound plays, when sound finishes change scene

#

so far, sound plays and when it finishes it changes scene

#

but i want an image to cover the screen as it plays

#

preferably flashing between to images but that's just a bonus

humble pike
#

Alright.
You don't need two scripts.
But the one script you have, will also need to reference the UI GameObject which is a child of a Canvas

#

If you have problems with tutorials, you can post the link + timestamp + question and people will help you with it.

jade arch
#

the problem is that i can't find a tutorial for my specific issue

#

so i asked the server, because they can fix specific problems

humble pike
#

Indeed, I see, though I did find this one
https://www.youtube.com/watch?v=UVUMqss4A34

In this Unity/C# tutorial I show you how to make an image appear on a trigger event using the UI system, this is a really easy feature to add but really important in getting to understand collisions and more!

·························································································

🔥 INSANE UNITY SAVINGS 🔥
🕹️Unity Procedural Wo...

▶ Play video
jade arch
#

yeah that's the exact one i followed

#

but it still doesn't work

#

because i had a premade trigger that already does things

humble pike
#

have you watched it a second time, and made sure you have done all the steps?

jade arch
#

yeah

#

but it's not working

#

so, i need to know how i make it appear

#

the code works fine

#

but the image doesn't appear

humble pike
# jade arch because i had a premade trigger that already does things

Whenever you have a problem, you need to simplify the issues.
Don't follow tutorials with your live project - Make a project for following tutorials.

The first order of business is to make an image appear on the screen. This is achieved entirely without code.
Once that is done, all you have to do is use code to make it appear when/how you want.

I will now take the time to watch this video tutorial, and we'll figure out what it was that you missed. (To my experience, SpeedTutor tutorials do work)

#

brb 10-15min

jade arch
#

the problem is that im a noob

humble pike
#

In code-beginner we are experts on helping noobs.

#

I can't imagine what it's like learning programming and game dev while suffering from Covid.

From looking at the tutorial and thinking about your previous code, there are at least two major things you missed.

  1. Creating the UI Image game object
  2. [SerializeField] for the variable
#

the second one we fixed

#

go to 1:29 in the SpeedTutor video to fix point 1

jade arch
#

ok hang on

#

so instead of adding image to the trigger, i add it to the game and refer to it?

#

i already have that?

#

doing that just adds a new image to an already exist canvas but it's still not visible

humble pike
#

I'm not sure what you mean by that.
Right now, just create the UI image object, and make it look like any image you have on hand.

#

No code.

jade arch
#

the image doesn't appear tho

#

it's not there

#

it's invisible

#

when i add it

#

it's just simply not there

jade arch
#

ooh, the image is there now

#

but idk how to make it invisible until the trigger

humble pike
#

holy shit, pardon me, I've been multitasking

#

Alright, so you are now able to see the image

jade arch
#

i dragged it to the position where the player will be at the trigger

#

this is a 2d game btw

humble pike
#

You can disable it by either disabling the Image Component, the game object itself, or the parent Canvas

jade arch
#

what's the best way considering in the script there is a function to enable image

humble pike
#

Canvas is probably best, if you are to add more elements to the image

jade arch
#

customImage.enabled = true;

#

is the line to enable it

humble pike
#

I don't think that's right.

jade arch
#
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class knowcollide : MonoBehaviour
{
    [SerializeField] private Image customImage;
    public AudioSource playSound;
    private bool _triggered;

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            Debug.Log("hit detected");
            _triggered = true;
            playSound.Play();
            customImage.enabled = true;
        }
    }

    private float frequency = 1.0f;
    private float timer;

    private void Update()
    {
        if (_triggered)
        {
            timer += Time.deltaTime;

            if (timer >= frequency)
            {
                timer = 0f;
                _triggered = false;
                MyFunction();
            }
        }
    }

    private void MyFunction()
    {
        SceneManager.LoadScene("menuofthought");
    }
}```
#

it's what the tutorial said to do

#

but if there's a better way lmk

humble pike
#

Where did the tutorial say that?

jade arch
#

icr

#

btw in game i can't see the image

#

only in the editor

humble pike
#

screenshot your Canvas settings

jade arch
#

idk what's happening

humble pike
#

when in Play mode, press Pause
can you make the image appear somehow?

#

(in Scene View)

nova zodiac
#

Instead of adding an image, try adding a button and see if you can see that

#

Image could be transparent or something accidentally, button won't be

#

If you see a button but not an image, this gives us useful info

jade arch
#

hang i'll try it one at a time

#

@humble pike idk how

#

do you have a suggestion on how to make it visible

#

@nova zodiac i also don't see a button

nova zodiac
#

Yeah I'm guessing your canvas is positioned wrong then, these kinds of things are nearly impossible to troubleshoot via text though

humble pike
jade arch
#

oh yeah

jade arch
#

it's way off away from the camera

nova zodiac
#

Make a new one then

jade arch
jade arch
#

it always appears away from my game

humble pike
#

If you're comfortable with it, compress the entire project into an archive, then delete the Library folder (90% of space) within the archive
so we can launch the project for ourselves.

jade arch
#

the tiny black specks in the corner are my game

#

also i'd rather not give you my game because i won't learn anything if you do it for me

#

i'd rather you told me what to do

humble pike
#

We won't send the solution back - it would just help immensely with diagnosing the problem

nova zodiac
#

Right now we're having to ask random questions to someone who we don't know can answer them properly, nearly impossible to debug as I said earlier

#

So a project would allow Rov to quickly check it out

jade arch
#

i get it, but im not comfortable doing that

#

i can show you whatever you want but i don't want to send the whole thing

#

this is the canvas tho, it's movement is greyed out

#

idk why

nova zodiac
#

That's fine. I don't have time for 21 questions though. GL

jade arch
#

hmm, what if i make the UI part of camera?

humble pike
#

Change your Editor layout so that you can see Game View and Scene View side-by-side.
Keep the Canvas selected, and visible in the inspector.
Then enter Play mode and screenshot the case of the image not displaying, while seeing the object in the Hierarchy, so that I can see if it is enabled or disabled.

nova zodiac
humble pike
jade arch
#

hang on, im trying to readd the image

humble pike
#

Hm. He's on a 2019 version.
I'm not sure if things were different back then, but it does seem different from the screenshot above.

jade arch
jade arch
#

anyway there's my screenshot

humble pike
#

/joke

#

is this the image?

jade arch
#

yeah

#

temporary image

humble pike
#

click the ui game object with the image, and screenshot the inspector

jade arch
#

the ui game object?

humble pike
#

the game object with the image component

jade arch
humble pike
#

it needs to be the child of a Canvas, not the parent

jade arch
#

it is

#

the canvas is the parent

humble pike
#

Not in the screenshot

jade arch
#

image is child of canvas

#

jomp = the collide box if you mean that

humble pike
#

mindfudge - I asked that you click the game object with the image component

jade arch
#

not im very confused

humble pike
#

I need to see the inspector of the object with the Image component

#

which is the Image game object (child of a canvas)

#

Clarification: Game Objects are containers that house Components

#

MonoBehaviour scripts are components

#

Image is also a component

jade arch
#

so which object do you want me to click there

humble pike
#

Image

jade arch
#

ok hang on

humble pike
#

screenshot the Color of the image
(click the color bar next to Image > Color)

jade arch
#

colour?

humble pike
#

click the grey color bar

jade arch
#

are you trying to show me how to change the colour?

#

or to check if it's full alpha?

humble pike
#

no, I want to see the numerical parameters of the color

#

such as alpha, yes

jade arch
#

alpha = 255

#

i think the canvas is the problem, but idk, i can't move it

humble pike
#

I have an idea as to what the problem may be

#

it is an Overlay canvas

jade arch
#

oh?

humble pike
#

separate it from its parent

jade arch
#

seperate what from it's parent

#

the image?

humble pike
#

the Canvas is the child of another game object

jade arch
#

child of the box for colliding yeah

humble pike
#

Parent/Child relations means their Transform properties are interlinked.
But the Canvas is a Camera Overlay type, and could conflict.

So simply unparent them. There is no reason for them to be linked.

jade arch
#

idk how to unpair them

humble pike
#

drag Canvas to above the parent in the Hierarchy

jade arch
#

alright cool, i unparented

humble pike
#

You probably need to adapt the code to reference the Canvas > Image

jade arch
#
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class knowcollide : MonoBehaviour
{
    [SerializeField] private Image customImage;
    public AudioSource playSound;
    private bool _triggered;

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            Debug.Log("hit detected");
            _triggered = true;
            playSound.Play();
            customImage.enabled = true;
        }
    }

    private float frequency = 1.0f;
    private float timer;

    private void Update()
    {
        if (_triggered)
        {
            timer += Time.deltaTime;

            if (timer >= frequency)
            {
                timer = 0f;
                _triggered = false;
                MyFunction();
            }
        }
    }

    private void MyFunction()
    {
        SceneManager.LoadScene("menuofthought");
    }
}```
#

but how

humble pike
#

Hm. Before that, is customImage refering to an Asset or the Image game object's Image component?

jade arch
#

i dunno

#

there is no image component

#

as much as that would be fun, there isn't

humble pike
#

the image component is on the UI game object (child of the canvas)

#

If customImage is referencing the image asset file
then the following line is wrong.

customImage.enabled = true;
#

Because that would be like disabling an asset. I don't think that's a thing.

jade arch
#

so how do i enable it

humble pike
#

customImage is used to tell the Image component which asset to render
so you could have an array of customImages[] and swap between them.

It is the image component, or it's game object, or Canvas, which must be enabled/disabled.

jade arch
#

my brain is worn out from thinking, i just need to find a way to make the image appear when collision happens lmao

humble pike
#

Running out of steam and time here as well.
Try this. If it doesn't work, change the type of _imageAsset from Image to Sprite. It's been too long for me to recall specifics.
https://gdl.space/telobecufe.cs

#

You'll need to drag'n drop the canvas and image objects to the script

jade arch
#

ok cool, it appears in the scene but not the game

#

when it collides

#

so that's way better

#

we're getting somewhere

#

but i still don't see it in the game

humble pike
#

I really think you would benefit from recreating the project in 2020.3

#

less bugs, improved features, and best of all - exactly what the majority of people are used to

jade arch
#

well, i'll do that once i get it to appear in game

humble pike
#

but if you just want to get done, I guess there should be a solution available

jade arch
#

so far, it works well

#

just no image in game

humble pike
#

You could back up your project, and then upgrade it to 2019.4.40f1

#

in case there was a bug with UI in 4.20

jade arch
#

i feel like that's a bit risky

humble pike
#

not if you back it up

jade arch
#

considering im about 95% of the way with the project

#

i'll just think about a way to solve it, you can too iyw, and if there's no other way we'll do that

humble pike
#

right-click the Project folder and compress it to an archive, or simply copy the folder and put it anywhere

#

then it is backed up

#

and you can try whatever you want

#

I have nothing else to contribute with. I'm having a break from game dev right now, and I'm long rusty on UI.