Why cant I add keyframes to my animator in Unity3D? - c#

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

Related

Button Command On click() Isn't enabling it's Image

I am trying to do something like X and O game, and I want the image of button be showed if it was pressed but it's not working, I made sure that button is working by reversing the command it worked fine! Here is screenshot
I tried to reverse the command and it worked so the button is working fine
Have in mind that a UI.Button requires at least one active and enabled visual component (Image/Text/etc) with RaycastTarget enabled ... I suspect since you disabled the image you simply disabled the interactions with this button
=> solution could be to simply have two Images like e.g.
- Button (with Button + Image component)
|-- Icon (with Image component)
The Button object is your main button with a background image - can be completely transparent, but can also react to interaction and have color for hover, press etc. This you always leave enabled and here you enable the RaycastTarget.
Then in Icon you assign the according circle or cross sprite and can enable / disable it accordingly. Here you can also deactivate the RaycastTarget to save some performance. You could even have two different child icons according to the sprites then you don't need to assign the sprite on runtime either but just activate according child object

Button seems to animate instead of the others

Here is my UI structure in the Hierarchy:
And here is how it looks:
So basically, when I click the first button, its color changes on click as expected. However when I click the second or the third one, the first one also displays the click animation, instead of the one I clicked.
Here are some things I noticed:
The buttons do register a click as expected.
When animating the button further than the default (by using custom timeline animations) the behavior is slightly different between the first and the second + third ones.
Things to note:
I am using a horizontal layout group on the panel with the following settings:
Each button has a TMP image inside with the same size as the button itself.
I theorize that the HLG is the problem here, but I've tried many settings and the result stayed static.
If you need any additional information, please ask.
Turns out the problem was that the target graphic on the buttons were all set to the first one. That's why they still registered the click properly even though the visuals were messed up.

How do I set Realtime Shadow Colour through script?

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.

Unity Prefab Issue, different reactions from different prefabs

So I've hit a wall in a unity project, and I've been unable to even find a similar problem. I'm not sure how to easily describe it, but here goes:
I have a prefab (a simple 3D object triggered on mouse click/finger tap). It is meant to act as a button (it cannot be a UI button for various reasons). I have a bunch of them. Each button has a script attached, so that when the button is pressed, it will display some text and and some images. However, this is not working.
To test it, I put down a few of these buttons. I filled in the script box for two of them, lets call them A and B. They were directed to the same UI elements, but each was given a different set of images to produce. However, when I test it, it only calls the images from B. If A is the only one set up, all the buttons call from A, even without a script attached.
I need some way to refresh the assigned starting "values" for the variables. So that it will pull from what I assigned them in the editor only when clicked on, and not before. Any help or suggestions would be appreciated.
Try this link Instantiating Prefabs from the unity site.
A possible solution would be to set a global Boolean variable for each button (prefab). If button 1 is active, set the variable to true and in for buttons 2 and 3 make them turn to false for inactive.
I suggest designing your script this way for each button. After the button is pressed refreshed the values in the variable for each button and check these values again once a button is pressed.
You seem to be almost there.
public class A : Mono {
public ImageToShow Image; // Assign this in inspector
void OnMouseDown() {
Image.DoYourThing(); // Do whatever you need to here for the image
}
}
When this is on many different "Prefabs" if you handle the prefabs correctly, each button will have its own instance with its own reference to the image you assigned inside the inspector.
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
Link for OnMouseDown.
Each button can have the SAME script, you just neeed to make sure that each prefab instance you have SAVED has the correct image assigned to its script.
Hope this helps.
Edit: Doing it this way, each button will be "active" but wont do anything if not tapped. If you tap or click an inactive game object (which is your button because its not a GUI element) no method on that object will be called.

Change background of toggle button when it is pressed

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 :)

Categories

Resources