I'm trying to change the Realtime Shadow Colour, which can be seen in the Lighting window under the Scene tab.
Now, I can change it in the editor, but I seemingly can't for the life of me figure out how to change it through a script during runtime.
I have tried changing RenderSettings.subtractiveShadowColor, but turned out it wasn't the one.
Suggestions/solutions are appreciated.
You can alter that setting by using RenderSettings.subtractiveShadowColor, you simply set that value to a Color like so:
RenderSettings.subtractiveShadowColor = colourValue;
Additionally the RenderSettings class is where you'll find most of the variables that are displayed in that window as well.
Related
I am creating a custom editor window in Unity. I want to have a label change color when the mouse hovers over it. To accomplish this, it would seem that this should work:
GUI.skin.label.hover.textColor = Color.red;
GUILayout.Label("My Label");
But the label still displays as normal with no effect when I hover over it with the mouse.
I've also tried manually creating GUIStyles and passing them as an argument to GUILayout.Label with the same result. If I change the normal state, however, I see the color change.
Is the hover state supported for labels, and if not, what controls is it supported for and how would I find out this information? It seems absent from Unity's docs.
You should be able to use GUI.skin.button if you are only interested in changing the text color.
var myStyle = new GUIStyle(GUI.skin.button);
myStyle.hover.textColor = Color.red;
GUILayout.Label("My Label", myStyle);
However, this has the side effect of taking all of the other qualities of the button style. Your label will look like a button. In theory you could change the background image for all of the style states and make it look not like a button, but doing so for the normal state reverts the hover behavior to that of a label style. This answer in the unity Q&A seems to be the most insightful explanation for why hover does not work (at least, not usually) but normal and active do.
In short, unity has special code for built in GUI styles that have hover over effects that force a redraw when the mouse passes over them. This seems to somehow be tied up in the normal style state for certain special styles, such as GUI.skin.button. The result, there is no option to have custom hover backgrounds, and anything that does need to have a custom hover text color must have the same background image as one of the built-in button styles.
I have a Unity3D animation, but, I can't add keyframes, it only gives me the option of Add Animation Event.
I also noticed that in the Animation component of the object, It doesn't allow me to check the box of enabled, If I turn it on, the checkbox becomes red and when I turn on/off the record keyframe mode the checkbox automatically unchecks...
I dont know if it could be related, but, this object was created copypasting of another object that has animations, I just deleted all of them and created new ones, but I dont know if this could have affected the object, because I have 2 objects create the same way, and they allow me to put keyframes.
You should set up your animation like the following:
Select the object you want to animate.
Go to the animation window, click 'Create'.
Save the animation to the desired folder. You should now have an animator file and an animation file.
Be sure the object is selected and add the desired properties on the left and everything should work just fine.
Hope this helps
I have 2 Canvas: one for Login, one for Register.
This is Canvas of Login:
When register button is clicked, i change and call Register Canvas:
But it gets blurry. I use same Unity config in both Canvas.
I disable and enable Canvas via C# script:
void TaskOnClick()
{
CanvasLogin.enabled = false;
LoginValue.text = "";
PasswordValue.text = "";
CanvasRegister.enabled = true;
}
The problem only occurs when I enable Canvas via command/script, if Canvas start enabled, the blurry dont occur.
Scale Config:
And it's funny that during the execution if I change the aspect of the screen and return, the text backs to normal...
The problem is not with second canvas, the problem is when i enable it
via command/script
I just came across this same problem and as this was the first result when I searched I'll add my answer. I had a GameObject with Canvas and CanvasScaler components.
I found that you if you disable / enable a Canvas at runtime you need to update the CanvasScaler too. In my case I disabled / enabled the CanvasScaler also. Setting any value on the CanvasScaler would probably set it to dirty and cause update.
As your problem is only with one of the canvases, you might want to check the attached Canvas Scaler components. It seems like the scaling on the second canvas is not correctly configured.
You can just copy all of the component's values from your first to the second canvas, with the dropdown menu from the little gear icon in the upper right corner of the component in the inspector window.
The easiest way:
use gameobject.SetActive() instead of canvas.enabled
I see there is already some questions on this matter, but they are not using unity3d or are using the old UI method of unity.
I have a toggle button with a specific background and I want that background to change when the toggle is off. I tried to do this using the inspector and setting a function to apply a different texture to the button when it was off, but did not work.
Do you have any idea on how to accomplish this? I am attaching what I tried.
The background of a toggle is just an Image
so it's this simple, in a script have
public Image theBackground;
you can then change that in any way you wish!
if you wish, have a function
public Image theBackground;
public Toggle theToggle;
public void ChangeBackground()
{
if (theToggle.isOn)
... set theBackground as you wish ..
else
... set theBackground as you wish ..
}
which sets it appropriately. Look in the toggle and drag that function to the OnValueChanged.
Enjoy!
I just ran into the same problem. What I did to solve it was the following:
When you place the Toggle on the Hierarchy, you get
Toggle
Background
Checkmark
Label
What I believe the toggle script does is modify the checkmark object (to make it appear or not).
So I replaced the Checkmark components (Rect Transform and Image (Script)) with the Background components.
Basically, just Copy component > Paste component values from Background to Checkmark.
And then, switch the Image Colors for both to the desired colors. Now when you Toggle in-game, you'll see it changes colors.
I know it's been a really long time, but it might help others :)
Situation:
I'm working on a new application that starts on opening a timer, when the timer ticks a progressbar loads.
What I want to do:
The basic thing I want is just change the color of the green bar. For example to blue.
My Problem:
I tried to change the color, if I look in the Properties Window of my progressbar, I can change the BackColor and ForeColor. Exactly as I did.
Now, I'm sure I did change the color but the changes doesn't seem to affect the progressbar.
It does not seem to change at all.. It still stays grey and green.
Is it possible to change this?
Maybe I need some code(C# or .NET)? (no need to tell the exact code, some basic pricipe is good)
Thank You
Locate the following line of code within your solution (tipically in Program.cs):
Application.EnableVisualStyles();
Comment out this line. Now the color of the progress bar will change as expected, but the style of your controls will also change a little. I'm curremtly trying to find a better solution for this myself.