Smooth Coin Collection Animation DOTween using Unity UniTask async await

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and yeah you see it's really nice right now hi let's start making the coin collecting animation we do twin and irritas in this video I'm gonna use the access code casual game GUI and I'm gonna put the links down in the description below if you're interested you can check it out first I will show you the animation stack that we are making so first we're gonna spawn some coin right here and then we're gonna move those coins toward hours money label right here and then we're gonna do some effects such as bouncing this value up and down and then we're gonna update the monetary values as we have now let's get started in EVD I'm going to create a C sharp script and I'm gonna call it collecting coin in here first I'm gonna lay out those steps we make sure that we have this step clear before we start coding but first i'm gonna spawn the coin to a specific ation wait random values right there so we don't want all of the coins in the same location is we want to tweet the value a little bit next after this we're gonna move all the coins to be uh how about we I was correct coin labels let's assume it and then we're gonna animate the reaction when collecting coin first let's start by spawning the coin to the specific location to do that I'm gonna have some View first I'm gonna FIFA and next I'm gonna have the small location and then I'm gonna have the coyamans I'm gonna have to say the type of in pressure and because we want to tweet the values a little bit so all the coin would not respawned in the same location I'm gonna add some values add some Randomness to it let's say mean X and Max X similarly I will put the y values always mean y and must what in here let's start by creating a for Loop I'm going to pass the chord a month and I'm gonna create or coin by using instantiate I'm gonna put the coin V5 right here and I forgot to add the patterns of the coin so in here we actually having the coffee Puffs as the children of the canvas so we must provide the parents and I'm gonna pass the coin parent here and then I'm gonna beside the position is equal to spawn location the options position okay now let's see in the editor I'm going to create a new object I will call it collecting coin and I'm going to reset the volume now I'm gonna trap it collecting card right here and in here I'm gonna assign the coin prefer for the spawn location I have the spawn point right here over there in here and after the side that you can have it anywhere that you like I'm gonna drag this small location right here and in coin patterns I will simply add this Lobby game object let's start and requirement I will call it it now let his play you will see that's eight coins has now been small but they are spawn in the same location right here what we're gonna do next is we're gonna add some randomness to make sure that they will have a nice smooth effect when they are spawn so in the follow-ups as we instantiate the coin instead of assigning the position of the coil as we have to respond to this one location I will right earn values I will call it exposition and you can call it whatever you like but for simple I will just score it and it's going to be spawn location Exposition dot X and and then I'm gonna post the random dark range and I'm gonna pass the Minix and the Maxi right here similarly the Y position will be equal to Small location that position dot y and equal to means Y and mass y and instead of assigning to this one location I will create new beta 3 and I'm gonna pass the X position and the Y position so because we spawning the coin inside the canvas we will necessarily have to pass the sales position right here but uh otherwise you should have it and I'm gonna click save back in unity I'm gonna twist some value let's call it minus one one and in here the square is minus two and two let's see you will see that the coin now being spread out like this instead of focusing in one location let's start over there we go now we have a different formation because we have asked some Randomness to a function and I just want to taught us we can change every value in here as we want instead of having to turn off the play mode and start again we can actually move this actually we will move all that quick refactor and short method and we're gonna reflect the list to another method and instead of invoke the method in a start method we will even see button attribute form knowledge attribute this will allow you to invoke this method in your inspector and you can click many things you like it is really powerful if you guys do know how to use naughty attributes it is an amazing tool and it is like Odin but it's free I have done a video about this and if you want you can check it out so do testing different combination of our Randomness in the x y coordinate we will start adding the recess mechanism I will create a list let's call it coin and is equal to new list and when I spawn a coin I will add those coins to the list and at the start of this method I will reset it I will create a follow then I'm gonna destroy the coin also I'm gonna clear the list in the editor we can see that we have already buttons it is inspector this is thanks to the naughty attribute package and every time we click this button we will invoke the methods collection coin uh I think I'm gonna change this to collect coins I think let's be much better and now when I hit play and I'm gonna click the correct coin you will see that is now spawn as we expected and the amazing thing is as we can click again and you will see that now has in a different information we can also tweaking those values like in here I want Chinese to 16 coin and I'm gonna taking those value to find out that work the best for the game right here and it's up to you to select the suitable value for your games and in here I just have some demonstrations as you could do that after tweaking some values I see that I can select all this combination and I think it works best for me and let's see how this works start to play mode and I'm gonna click collect coins and change this to 16 for better the position you will see is now it's quite amazing now next after all the coins has been spawned what we're gonna do is gonna we're gonna move the coin to the end position and to do that I'm gonna use the twin with Unitas and if you guys do know how we can use Duty with any tasks I have an amazing tutorial and you can check it out and learn for yourself in here I will add firmware transform and position and uh after we spawn all the coin we will look through it because we already added coins to the list we will use a simple for Loop call it dot transform and then we're gonna use to move this time I will pass it and position and the duration well I will just move the fuse and make it zero to help us debug it and sometimes we can just tweet the value in inspector and I'm gonna pass the duration right here what is this transform with the tree oh and position that position okay let's save it in EVD we're going to click collect coin and then I will change the values about duration of the twinning to V2 and for end position I will looking for the coin symbol right here and if you guys do know it uh you have to click this mobile to be able to select this yeah this is simple and I'm gonna ask the simple to the collecting course code I'm going to say let's play I'll click collect coins you will see that is already spawned but now it's gonna move right next right in the middle of the labels however we want to moist right here and you will notice that the side of the coin is somehow smaller than the side of the label what we should do is we should make all of that in the same size let's play again spawn the coin and move it right here to fix the issue we're gonna assign the parents of the coin instant right here to the object that have similar hierarchy order and similarly for end position I'm gonna add the image right here to it so up to all the coin had been spawned it's gonna move to the collectible right here now let's display I'm gonna click collect coins you'll see that the side has a little bits larger than label it is because in here the coins label have the width of 76 and the high of 83 however the coins instant have the width and height of 100. so what we should do is we're gonna select the coin FIFA and we're gonna change it to 76 and D3 now I will run the game in connecting coin I'm gonna click collects coins you see that it's now exact we want however you can see that um the animation is quite fast in here I want to slow down a little bit maybe that's after we spawn all the coin we're gonna wait a little bit and then we're gonna twin all those coins to this position let's do it in collecting coin I'm gonna add a scene keyword here and then after all the coin being spawned I'm gonna await and I'm gonna use it in Italian and I'm gonna party times from seconds I think that's correct and I'm gonna wait for one seconds so basically always call it is we're gonna wait for a second and then we're gonna continue our logic let's take a look in the editor I'm gonna click play cracking coin you see that is gonna wait a little bit and then it's gonna move to the coin label and it says to be in here additionally I don't like the way that's all the coin moving in the same time I want it to move like sequentially like one quarter time I could do that by putting the away code inside the low function where I'm gonna look for all the coin into moving to the end position basically I'm gonna copy all those code right here and then I'm gonna waste something like zero point zero point zero five seconds and let's see how it's work I'm going to hit play I'm gonna click like coin he spawn and you see that it's gonna move sequentially the following thing that we're gonna do is we're gonna have to wait for the reaction of collecting coin happens by mousing the coin label and I'm gonna do that just for you for testing I'm going to create another function let's call it um react to collecting coin and I'm gonna put the button attribute right here to help us testing the method in the editor in here I will get the end position which is the label and I'm gonna use blue punch rotation which is one of the lutein function and if you guys have no idea what it is just follow along and I think when I show you the example you will understand much better and in here I'm gonna pass the punch with this inverter tree I'm gonna have create a new better and I'm gonna call RC values 1.5 5 and 0. okay and the duration um how about zero point one all the parameters left like Roberto or the elasticity I will leverage default value in the answer I'll click play and I'm going to click react to collecting coin why is nothing happen my apologize I've still reaches I think um my mistake is using do punch rotation and what we should do is click on reduce unscale right here and let's go back to the C in a later I'm going to play and I'm click react to correction coin you'll see that's a spell thing and it's going back here there we go so what we want to do is when we click or like coins we want to spawn the coin and each time is coin move to the right here and I think and that's my sense for you guys to do that we're gonna reflect a little bit first we will move the code here into a separate function um moves coins right here and instead of tasks I'm going to return the editors type and I'm going to wait for it to happens in here I will also separate this into another method let's call it move coin tax you will notice us there is no the s after the coin in here I'm gonna create a list and I will say smooth coin Plus which equal to new list of images and in here I will change the ties from boy to ebitos instead of just calling the function I will ask the return value to the McCoy type list I will away for the training to be finished and I'm gonna pass two Unitas right here and then I will react to Coalition koi so the logic here is after each coin reach to the end position the coil level will be bouncing and that is my logic in my mind let's take a look at the editor I'm going to click collect coins wow you will see that because the DuPont's function between the value form different from the original and then it's gonna go back but because we call this method a long time the original values is not the same anymore so the resource in here is the collable is getting quite large and don't worry we're gonna fix us in the reactive collection coil I will change the return value to Unitas and then I'm gonna create a global variable and I'm going to request I'm sorry I'm going to create a field and let's have it a twin I'll be call it um reaction chord ration twin so um the logic in here is us we're gonna tweeting the values in this case we're gonna scale the call label but however we don't want it to be overlapped like when we call the reaction to collect coins again um if the tweeting it still exists we will not executing the meters I will assign the twin correlation twin equal to this I would have if coin reaction twin is equal to no and if not I'm gonna assign this and in here I'm gonna await four this training to be finished and I'm gonna put the away keyboard here um coin reaction twin to limit us so after we await it we will set the coin reaction between equal to no so that's after the bouncing effect is finished we will bounce that again now I will delete this but then I should be right here and let's take a look at the editor how we play and I will click collect coins you will see that it is although it's quite fast now um it is not have the same Arrow as it has before to make a really nice acceleration effect I will ask it is in Russian by using set is and I'm gonna pass is dot in our elastic you can check it out all the Instinct method here I will put the link down in the description so in here I would use the in-l elastic which is gonna slow a little bit down but it's gonna move it up so let's take a look at the dancer however I will also notate that the scale of the coil level is quite large and I'm gonna move it to 0.5 instead of 1.5 let's see collecting coin um one thing I noticed is as the coin which has been spawned has now had the upper layer then the coil label and we will change that by creating an parents object and which in here the call label will have the better layer I will create and new game object and I'm recording my parents and I'm gonna move in here and in the collection coin I will RT koi parents to decoy parents now let's take a look I'm going to click collect coin you will see that's is now under the callable similar to the Instinct methods of the Corn reaction twin I will also add the Instinct method to the translation twin and this year I'm gonna use this Dot impact so in the instinct.net you will see that it's in Black the coin will be slow down a little bit is even move right back the opposite direction but then it will go back up so let's see this is like in the editor I'm going to keep playing I'm going to click collect coins you will see this is have a very nice isolation effect this will charge something like a recharge the weight limit and we go to the collabor right here and after we finish the twinning animation the coin will be react the next thing we're going to do is we're gonna update the values right here after each coin had reached the destination so let's do that in the collecting coin class I will ask another field which is this macro uh use UI and I would call it coin text let's make it simple and I will also keep choice of how many coins that we have collected with in coin I will create a methods let's call it Set coin and I'm gonna ask the parameters value Bitcoin will be equal to the values and then I will also set the value of the coin to the context in here we will await for the reaction to be finished then we will Set coin to be coin first one right here and then when we reset we will also to be set the core values to be zero then hit play in here we're gonna spawn eight coin let's click collect coin oh I forgot to assign the text map Pro so we will select this which is the I think this is Tech value it's a tech value the corporate we just curated the text value to the coin type selectric set and I'm gonna click play in collection coin that his collect coins you will see that it is gonna have the tuning effect now we will change the coil duration I'm sorry Shane requirement to 16 to have a better effect so let's take a look if we are correct the coil will be recessed to zero and then it's gonna go back up again let's see there you go you will see that after we chaining the coil among the effects start to look nice right now in here for a better optimization after we finish effect we should destroy all the coins that we have just spawned in here I will change this to game object and record uh coin instant to avoid any meet understanding and then in here I will pass it coins dot I and after we are wait for it to be finished I will add the demo check I will call with 10 it's going to be the coin instant and then I'm going to remove it from this move coincidence and then I'm gonna destroy it so let's see in the editor in it later I'm gonna click play and I'm going to click collect coins then I spawn all the it and drag it here and now the tests have been updated however you will not see this but something is quite wrong here I will show you in a better example in here instead of waiting for 0.0.5 seconds I will wait for one second the logic here is as in this Loop we move the coin and then we wait for the one seconds and then we move another now let's take a look in editor you see what's been wrong I'm replay and I'm going uh and I'm gonna click collect coins we spawn it one two three four five you see that there's some kind of arrows here three of them doesn't move so what's wrong the reason for that is we have removed the coin instant and we destroy it when we still looping it d looping the coins collection has now been modified which results in the boxes we have so I already made another video I will put the link down in the description so basically what we will do is instead of using normal Polo we're gonna use the reverse follow so when we modifies our collection we gonna destroy it but then because we look on from the bottom to the top The Collection doesn't change the order hello face is right here and I'm going to paste all the code right here and start in the editor let his play and I'm going to click collect coins then one two three four five six seven eight do you see now all the Logics have been correct and you will and you can tweet all the values you can wait any time that you want but see there's nothing chance unless before where we wait longer time B incorrect behaviors start to appear when we spawn 16 coin we gonna start to note it we have a really nice effect let's hit it and all gonna jump and it's gonna pop ups and the updates value will be here however I think the entrance of the coin is a little bit boring so the chains are in the collecting coins I will also add the do punch extension method to the coin instant so let's do that I will the coincidence that transformed dot to punch but then I will to punch the rotation of it in here I'm gonna punch for a vector 3 let's start at zero zero zero and the duration lets us some Randomness to it to make it small life random that range zero and then one the verbatore and the elasticity I'm gonna put this 34 values and then I'm gonna add the Instinct methods which gonna be is without impact just like the move pointers in here I'm gonna change this to Unitas and similarly I will 40 delete code in here to wait a little bit before The Leftovers coin start appearing I'm going to click save and let's see in the editor I'm going to click like and I'm gonna click collect coin you see that it's quite a little bit smooth now and I'm actually quite happy with it as you want to say that's you should also tweaking the Instinct method to see what's suit for you in here I could also and Chinese 2 is out he likes stick and and then I've also have a very nice effect and yeah you see it's really nice right now and I think you should do it to your games and see what is meant for you let's try again let's see again let's see how it is so far go like coins we spawn the coin and then we move up to label any values have been updated what I'd like to talk more about here is another box as I think I'm a file because we didn't wait for this twin to be finished there are cases that we move all the coins before we finish spawning I mean if the coil Monk Is small we gonna We're Not Gonna notice this but if it's going to be large it's going to be noticeable how we should fix that no matter how many coins has been spawned we didn't get any error so we will do that by creating a list scores in the tasks and I will correspond coin task list it's gonna be news in pass and then I'm gonna ask the twin emitter to the list right here and then the method I want to show you is Unitas that's when o so what we we're going to do is we're going to pass the spawn coin task list right here this method will be triggered after all the 3D methods has been finished so we want to control thus when we finish all of that we can actually forwards the next logic and do not have to be worried about any side effect and I can just remove the delay because it's gonna wait anyways then click save and let's see in the editor you will see that nothing has been changed our effects still look great that is the end of my video if you like it please consider like And subscribe and if you guys have any question please put it in the comments below and maybe you can if you really like it you can share to your friends thank you for watching
Info
Channel: NotJustUnity
Views: 3,644
Rating: undefined out of 5
Keywords: animation, Unity UniTask, Asynchronous Programming, C# Coroutine Alternative, Task Management, Performance Optimization, Unity Plugin, Multithreading, Async Await, Concurrency, Unity Development, Game Programming, Real-time Processing, Programming Paradigm, Code Efficiency, Resource Management, Unity Asset Store, Unity Game Engine, Programming Languages, Code Optimization, Unity Scripting, Dotween, Unity Dotween, Tweening, unity, game development, tutorial, dotween
Id: Zoivw8kXQOY
Channel Id: undefined
Length: 43min 33sec (2613 seconds)
Published: Tue Jul 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.