I am facing a problem while playing a animation which is already playing at the moment.
e.g. I am currently working on boxing fighting game in which when I punch twice, first time animation is played but second time, it doesn't restart animation.
I also tried turning off that animation if it is already running, not finding any clue regarding this problem as I'm beginner in mecanim animation.
Mecanim doesn't allow you to do this directly. A state can only be in one state at a time. Either at the end and fading out or at the start and fading in, but not both at once.
You can do a hacky workaround where you make two states with the same animation and alternate between them each time you want to play that animation. It's annoying to set up and makes it take more effort if you need to refactor, but it does work.
My Animancer plugin on the Unity Asset Store has a function specifically for this situation: CrossFadeNew will always fade the animation in from the beginning. If it's already playing it will automatically create a new state to fade in while the old one fades out. Feel free to contact me via the support email address listed on the store page and in the user manual if you have any questions about it.
Related
Automatic animation after the previous one in Unity - how to do something like that?
I mean, in my game, I performed the jump function and it has its animations, and how do you do that when it ends, the falling animation will start - that is, right after the jump animation,
Question: How can I start the animation immediately after two in Unity?
Please help!
Thanks to Unity's built in animator this is actually really easy to do without any code. All you have to do is setup a transition to the next animation after that animation plays. I'd recommend this tutorial to get started. (I've already set it to start at the part of the video where he actually talks about it)
I'm making a HoloLens version of the Epcot fireworks show, IllumiNations. What's the best way to trigger events like explosion animations, items appearing/disappearing, and making certain GameObjects increase or decrease in scale. I'm hoping there's a way to do it that doesn't involve coding each object to listen to the music for the right time as that would be very time consuming. I've seen a program similar to what I need called Koreography but I am broke so I cant afford an $85 program. Any help is appreciated. Thanks!
One of the simplest ways to do it without needing to code to listen to music is manually. You listen to the music, and make time markers along the music track with different indicators for each type of firework that you would want to explode at that moment. Then simply spawn each firework a few moments before should explode, and it include the complete animation + explosion noises, and destroy itself.
I have made a very simple hypercasual game everything works fine but after some few minutes of gameplay, the fps goes from 60 to 50 even the phone gets heated up. Similar to this question. I tried profiling but just can't see anything off. Tried even removing some UI elements but still no luck. Tried various vsync settings. Also, I had used this to display the fps. Even without it, the lag can be seen. Even if I just open the game and do nothing then after 5 minutes the fps will become 50. If go back using the home button and re-enter the game then the fps becomes 60 again. Using unity 2018.2.6f1. Never experienced this behavior in my other Android games.
Basically it was a faulty custom vertex shader which was applied to a plane to change the background color which changed color over time. I had not used the mobile vertex color because I was not getting the desired output. But now I'll stick to the mobile one.
The two symptoms you observed are very much likely to be connected.
The phone might heat up, as you are using its full power, which in turn makes the throttling kick in, reducing the perform
I've had the EXACTLY same problem. I was trying to fix it for a very long time. You said something about faulty shaders you use. And this is the key to solve our problem.
I use a 2-color gradient as a BG, so I have to use a shader too. Due to the fact that I'm a total noob in the writing "shader-code", I have to find something in the Internet. And it was my biggest fail)
To fix the problem and remove this fps drop you should remove your gradient and shader attached to it from the scene. And try to find a more optimized shader for 2D-game (or you can always write your own one c:)
I want to put a scene in Unity into virtual reality using Google Cardboard.
I used to be able to just drag a CardboardMain prefab into the scene, delete the main camera, use CardboardMain as the camera position, and CardboardHead to track where the user was looking.
After reading the release notes for the new updates, I thought I could drag a GVREditorEmulator and GVRControllerMain into the scene, and keep the normal camera.
Unfortunately, I can't figure out how to get the camera to follow my character with this new setup. (In this case, a rolling ball.)
If I change the position of the normal camera, it looks like it works fine in Unity, but as soon as I upload it to my phone, the user stays in the same place, while the ball rolls away. (The user can still control the ball's movements, but the camera/user doesn't follow the ball at all.)
I had thought that the chase cam demo would be useful, but that's only for Daydream, and I'm using Cardboard.
This trick seemed to work for some people. I tried in on a previous version of Unity and a previous version of the SDK and it did not seem to work. I may just need to try it on this new version, but I'm worried about going into the released code and editing it, so I'd prefer answers that don't require this.
Is there any way I can get the user to move in a Google Cardboard scene in Unity when I upload it to my iPhone?
UPDATE:
It looks as though my main camera object is not moving, making me think that something is resetting it back to the center every time, lending some more credence to the "trick" earlier. I will now try "the trick" to see if it works.
UPDATE: It doesn't look like the lines listed in the "trick" are there anymore, and the ones that are similar in the new program don't even seem to be running. Still trying to figure out what continues to reset the main camera's position.
UPDATE: Just got a response back from Google on GitHub (or at least someone working on the SDK) that says "You just need to make the node that follows the player a parent of the camera, not the same game object as the camera." I'm not exactly sure what that means, so if someone could explain that, that would most likely solve my problem. If I figure it out on my own I'll post back here.
UPDATE: Zarko Ristic posted an answer that explained what this was, but unfortunately the tracking is still off. I found out how to get Google Cardboard to work with the old SDK and posted an answer on that. Still looking for ways to get the new SDK to follow a character properly.
You can't change positioin of camera in cardboard application, position of MainCamera it always must be 0,0,0. But you can just simply made empty GameObject and make it parent of MainCamera. In Cardboard games actualy you can move parent of camera instead MainCamera directly.
Add script for tracking ball to MainCamera parent (GameObject).
This does not answer my question, but is a solution to the problem.
Do not use the newest version of the SDK. Use version 0.6
When building the app in Unity, do not select to have VR enabled under the build settings. (VR will still be enabled in the app.) (Credit: Zarko Ristic)
When putting the app onto your phone, if XCode prompts you to change any settings, you can ignore it.
In addition, disable bitcode under "Build Settings -> Enable Bitcode -> No" (Currently, this will not allow you to put your app onto the app store. I would greatly appreciate it if anyone has information on how to get it to run without doing this.)
Now your app should run on your phone correctly.
I am making a 2d game in Unity, and for the main character I have created 4 animations; up, down, left, and right. To do this I just made the animation and trigger them with a line of code like this:
anim.SetBool ("movingUp", true);
which would happen when the up key is pressed. This type of animation is easy to deal with because it is not based on time, but how long the player wants the character to be in that state. I am now trying to add an animation that is triggered when the character collides with another game object. I am not sure how to make it so the animation will play just one time and then go back to the other animation. Is there a way to trigger an animation to play just once in Unity?
Generally speaking you don't have to code your own controller, Unity already has that one and here is the link to official Unity tutorials how to use it. What you need is to fire off a trigger just like you did upon collision and check has exit time on that animation in the controller. After that you just guide the state back to the animation you want it to go back to. Again, accurate and thorough tutorials are found online on the term Unity Mecanim how to or Animations in Unity or something like that.
MAke an animator controller and add the 4 animations into it. then make a transition between them with the Boolean. Are you doing this as an automatic animation without triggering it?