loading...
آموزش کامل نقشه کشی اتوکد مدلسازی سه بعدی به زبان فارسی
3d Rener بازدید : 138 چهارشنبه 15 آذر 1396 نظرات (0)

 آموزش کامل یونیتی دو بعدی Unity Add animation stats

دانلود آموزش تصویری یونیتی به زبان فارسی Unity 

 

اکنون که ما قادر به پاک کردن تمام آمارها از پنجره ما هستیم، می خواهیم یک شیوه متحرک سازی هر یک را اضافه کنیم تا بتوانیم نمره نهایی خود را به بازیکن نشان دهیم. بیایید به بازی ما در کلاس کلاس اضافه کنیم و کد دیگری اضافه کنیم. ما قصد داریم یک راه برای پیگیری زمان بین هر یک از آمار و همچنین یک شمارنده داخلی برای تاخیر در مجموع داشته باشیم. اجازه دهید یک شناور عمومی به نام statsDelay ایجاد کنیم. ما این مقدار را به یک f تنظیم می کنیم. بعد، اجازه دهید یک شناور خصوصی ایجاد کنیم که به آن تاخیر داده شده است و ما این را صفر می کنیم. بعد، ما باید مسیر هر یک از آمارها را از طریق حرکت و نمایش آنها حفظ کنیم. بیایید یک int عمومی به نام totalStats ایجاد کنیم. ما این را به شش انتخاب می کنیم. بعد، بگذارید int عمومی دیگری را به نام statsPerColumn ایجاد کنیم و ما این را به سه عدد می دهیم. در نهایت، ما یک int خصوصیاتی به نام currentStat اضافه خواهیم کرد و از این برای ردیابی stat که ما آن را تحریک می کنیم، استفاده می کنیم. سپس، یک روش جدید خصوصی با نام updateStatText با نوع بازگشتی void ایجاد کنیم. در اینجا ما در یک اشاره به برچسب متن و مقدار متن قرار می گیریم. درون روش، ما قصد داریم راهی برای اضافه کردن stat جدید به متن برچسب ایجاد کنیم. ما این را با فراخوانی label.text به عهده داریم که با کلمه stat مطابقت دارد، ما یک فضای را اضافه میکنیم و از وضعیت فعلی به عنوان مقدار آن استفاده میکنیم. ما این را با افزودن یک خط جدید به پایان رساندیم. بعد می خواهیم ارزش را به یک عدد تصادفی تنظیم کنیم. باز هم، ما از plus equal استفاده می کنیم، در اینجا از کلاس تصادفی Unity برای ایجاد محدوده بین مقادیر صفر و 1000 استفاده خواهیم کرد. اکنون برای اینکه یک رابط کاربری به نظر برسد، می خواهیم نقطه صفر را بچرخانیم. بنابراین اجازه دهید با ToString تماس بگیریم و در D4 به عنوان یک گزینه منتقل کنیم. این به کلاس رشته می گوید که عدد را با 4 فاصله می گیرد. در نهایت، یک خط جدید را اضافه می کنیم، و اکنون هر بار که ما به updateStatText می گوییم، می توانیم برچسب و مقدار را در یک زمان به روز رسانی کنیم. بیایید یک روش جدید و خصوصی ایجاد کنیم، و ما این ShowNextStat را به آن دعوت میکنیم. در داخل این روش، ما میخواهیم تست کنیم که آیا آمار کنونی بیشتر از آمار کل منهای یک است. این است که ما می دانیم که ما به پایان آمار رسیده ایم و باید نمره را نمایش دهیم.

 Here we'll set the score value text to equal a random range. We'll set this to zero, and one with nine zeros behind it. This will give us 10 characters. So let's pad this to 10. If you remember back to when we did the layout, we also padded it with 10 zeros. Since this is the final score, let's set the current stat value to equal negative one and call return so that we exit out of the method. Below this, if we're still going through the stats, we're going to want to test which stat we're at so that we know the proper column to display that stat in. Here we'll create a condition for current stat to see if it's less than the stats per column. Inside of this method, here, we'll call updateStatText and pass in the left stat label and the left stat values. Now let's copy this line, create an else, and paste it inside of the else condition. We'll simply replace left with right and now we'll be able to move from the left column over to the right column as we iterate through each of the stats. The last thing we're going to want to do is increment the current stat by one. Now that we have our logic for displaying the next stat, we're going to need a way to call this. So let's create an update method and inside of it we're going to set the delay value to plus equals the deltaTime. The deltaTime is the difference between each frame that's rendered. As this increases over time, we're able to use this as a counter to tell when we should display the next stat. In order to do this, we'll need a condition that tests whether the delay is greater than the stats delay. We'll also want to test that the current stat does not equal negative one, in that case, we've displayed all the stats and the final score and there's nothing else left to animate. And now inside of this condition, we'll simply call ShowNextStat and reset the delay back to zero. The last thing we want to do below our open method is override our close method. Now, below where we call base.Close, we want to reset the current stat to equal zero. This way, when the window closes, it resets the counter, and when it opens, it'll immediately start animating. Let's save our changes, go into Unity, and test this out. If you run the game, you should now see each of the stats displayed with a random number and then the final score at the end.

تعداد صفحات : 136

اطلاعات کاربری