#UI Image Enable
1 messages · Page 1 of 1 (latest)
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.
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
hey, was afk a bit, sec
i think i found the gui but it's a white box that i can't move
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?
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?
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?
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
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.
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
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...
yeah that's the exact one i followed
but it still doesn't work
because i had a premade trigger that already does things
have you watched it a second time, and made sure you have done all the steps?
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
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
the problem is that im a noob
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.
- Creating the UI Image game object
- [SerializeField] for the variable
the second one we fixed
go to 1:29 in the SpeedTutor video to fix point 1
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
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.
the image doesn't appear tho
it's not there
it's invisible
when i add it
it's just simply not there
holy shit, pardon me, I've been multitasking
Alright, so you are now able to see the image
i dragged it to the position where the player will be at the trigger
this is a 2d game btw
You can disable it by either disabling the Image Component, the game object itself, or the parent Canvas
what's the best way considering in the script there is a function to enable image
Canvas is probably best, if you are to add more elements to the image
I don't think that's right.
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
Where did the tutorial say that?
screenshot your Canvas settings
when in Play mode, press Pause
can you make the image appear somehow?
(in Scene View)
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
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
Yeah I'm guessing your canvas is positioned wrong then, these kinds of things are nearly impossible to troubleshoot via text though
oh yeah
i can't move my canvas
it's way off away from the camera
Make a new one then
as in, idk how to make it appear
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.
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
We won't send the solution back - it would just help immensely with diagnosing the problem
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
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
That's fine. I don't have time for 21 questions though. GL
hmm, what if i make the UI part of camera?
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.
Should be able to set it up like this:
all UI is rendered by a camera.
Parenting objects has no effect that I know.
And Overlay mode automatically places the UI relative to the rendering camera.
hang on, im trying to readd the image
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.
he? lol
anyway there's my screenshot
I'll refer to you as the noob then. It's on a 2019 version. 👮
/joke
is this the image?
click the ui game object with the image, and screenshot the inspector
the ui game object?
the game object with the image component
it needs to be the child of a Canvas, not the parent
Not in the screenshot
mindfudge - I asked that you click the game object with the image component
not im very confused
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
so which object do you want me to click there
Image
screenshot the Color of the image
(click the color bar next to Image > Color)
colour?
click the grey color bar
oh?
separate it from its parent
the Canvas is the child of another game object
child of the box for colliding yeah
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.
idk how to unpair them
drag Canvas to above the parent in the Hierarchy
alright cool, i unparented
You probably need to adapt the code to reference the Canvas > Image
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
Hm. Before that, is customImage refering to an Asset or the Image game object's Image component?
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.
so how do i enable it
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.
my brain is worn out from thinking, i just need to find a way to make the image appear when collision happens lmao
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
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
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
well, i'll do that once i get it to appear in game
but if you just want to get done, I guess there should be a solution available
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
i feel like that's a bit risky
not if you back it up