I have been trying for some hours and almost finished reading all answers on Unity as well as on Stackoverflow. I still don't know how I can place that Pink Character shown in attached picture on to front of the Background. Can anyone please help me?
Image
There are many ways to go about this, you just need to test out what works for you and be creative. There are a few things that you can do:
Option - A
You can try to change Samus's Transform to a rect transform then set the z-index.
Option - B
Change the canvas render mode or sort order
Option - C
Add Samus to the canvas as an Image, then put the image above the background by moving it in the Hierarchy.
Option - D
as suggested by #pixlhero, simply make the background image a SpriteRenderer as well then move it behind Samus in the Hierarchy.
Thanks everyone for your help.
Here is how I solved the problem without Code
Solution:
Step 1: Go to Hierarchy -> Create Empty GameObject.
Step 2: Click on Add Component to add a Sprite Renderer to your Empty GameObject.
Step 3: I imported my character by dragging it into Unity Project Asset Folder.
Step 4: Add the character into Hierarchy and then add Sprite Renderer Component to your Character.
Thanks,
Related
I have a prefab of a submarine I made in blender. In this submarine there is a "altitude" screen which is basically a cube I scaled and painted black.
I can easly get the altitude of my submarine by doing sub.transform.position.y.
Now I want to put a "Text" over the screen with the altitude I am getting.
My question is : What is the best way to do it ?
In an Ideal world I would have a function like
TextObject putTextOnTop(GameObject the_panel)
that would generate a textObject that I would then update each frame with my value.
Thanks
There are multiple solutions for this.
There is an old 3D Text component in unity. This can do what you want. The Problem with this is, that you have only limited styling options.
A Better way is to use a WorldSpaceCanvas.
If you use this option, you have all TextMeshPro styling options.
Here is a video:
https://www.youtube.com/watch?v=GuWEXBeHEy8
The video is not very good, but i can't find a better one.
If you have any Questions left, feel free to ask
You can put the Text GameObject to be the child of the screen (Cube GameObject), there are 2 ways for this:
Set directly in Hierarchy
Create a prefab TextObject and save it in Resources with path: Resources/UI/TextObject. Then in the code, instance and add it as a child of the Cube using the following code:
GameObject textObject = Instantiate(Resources.Load("/UI/TextObject") as GameObject);
textObject.transform.SetParent(cube.transform, false);
Then, in the Update function you add the following code:
void Update()
{
TextObject.GetComponent<Text>().text = sub.transform.position.y.ToString();
}
Hope it can help you!
I'm trying to add the Unity Button Script to a 3d gameObject. When I tried this by adding it onto a cube, I can't get the desired behaviours. How can I get the 3d object to work like a button? In particular the highlighting colors, the click events. I was speculating that perhaps it uses the wrong raycaster, and if the raycaster specificaiton is changed some how it would work? Does anyone have a good enough understanding of the source code to explain if this is possible, and if so what I would need to do to achieve this? Thanks.
Rik
You could do it by using OnMouseDown() function. Here is the link Unity Docs
You will also need to add the image script along with the button script.
I'm newbie in Unity & I wanted to add a water to my scene but the water that I added looks purple and I got two error messages as well in my console which says:
Material Does Not Have A Color Property
So how to fix this issue ? There must be a problem with my shader texture however the material has the write texture.. Print Screens Are Below:
That's the graphics card's way of telling you it doesn't know which shader to apply your object.
Click on a mesh that is pink, and the material property will be set to none or missing. You'll need to remap the materials in your project to your pink objects, or drag the textures back onto your objects again.
You are seeing this pink color because a shader is missing or is not properly selected.
I'm sure the following is the error you'd encounter in the inspector:
This is how it should look if everything is correct:
I selected the shader in the file browser so you can check the location yourself.
Resolving the issue
The first thing you could try to resolve this issue is open the shader tab in the inspector and search the "Shader" dropdown menu for the water shader:
If you can't find it there the only option is to reimport the assetpack.
Or copy this shader from another project where you still have it.
I am trying to display the score for my game, however, my background sprite is drawing right over it. I have tried assigning some type of layer tag but I can't find one for text. Everything I try, the text is always hidden under the sprite for my background (and any other sprite for that matter). Is there a way to assign the text to be drawn over everything, I have tried looking at tons of sites in hopes of a fix but I can't seem to find anything. Any help is extremely appreciated.
From the hierarchy creation menu, pick UI->Text
This will add you 3 Elements to the hierarchy: Canvas, and 2 child gameobjects which are Text and EventManager. These are all needed for the proccess.
The text gameobject is part of the UI system Unity has, means that if done correctly, it should show over all sprites.
Programmatically you can change text by simply saying:
myUItext.text = "Text that will show on UI!"
Manually you can change position, font and text using the hierarchy view.
For further details use this video from the official Unity tutorial
I have once again problems with Unity. I can't spear much code due the level of secrecy agreement in the game I'm working on but I ran to this one annoying problem when running my code.
SO, I'm creating GameObjects in runtime when entering a certain view in the game. I have created a so called Reader for our game story which reads text from database, splits it to paragraphs, creates GameObject around that paraghraph text (setting text components etc. to it) and then adds that GameObject and its text to a story panel that shows all the objects as a scrollable view inside masked panel.
Hopefully you can keep up with my explanations :D
Everything works fine all the way to the point that the paragraphs are appearing correctly underneath the parent object (the view panel for the texts) and is shown correctly in the scene view, but... the problem is that, although i have made several checks in update loops, Unity just keeps giving random z position to the GameObjects setting them to
position z = -350
which makes them out of the player view and quite hard to read :D
I have debugged many times the position of the GameObjects in update giving it out z position 0 in every frame. This clearly doesn't mach the value the objects have in editor view during runtime...
Has anyone ran in to this kind of problem?
ps. I have treid to close and open Unity, load things again, nothing works.
oh and one thing to mention too is that to stretch the text to fit the size of text content and parent panel width I have used these as examples:
"Unity UI Tutorial - How to make a scrollable list" by rachetandclank3
Hmm... I somehow managed to fix this problem when I changed this:
this.paragraphObject.transform.localPosition.Set(
this.paragraphObject.transform.position.x,
this.paragraphObject.transform.position.y,0f);
to using this instead:
Vector3 newPosition = new Vector3(
this.paragraphObject.transform.position.x,
this.paragraphObject.transform.position.y, 0f);
this.paragraphObject.transform.localPosition = newPosition;
hopefully this helps others that also struggles with this kind of problem.
Source to the solutions: GameObject position.Set() not working
in Vector3 at z position try to change with gameObject.transform.position.z,
replace gameObject with the object name which position is changed mysteriously.