
اکنون ما آماده هستیم تا هر یک از دکمه های تعویض را وصل کنیم. بیایید به کلاس DifficultyWindow بازگردیم و آماده برای اتصال به آن باشیم. اولین کاری که ما انجام خواهیم داد اضافه کردن یک ویژگی برای تنظیم مشکل است. ما این را یک int int عمومی به نام مشکل می بینیم. و برای گیرنده، ما آن را به صفر بازگردانیم. برای تنظیم کننده، ما قصد داریم ارزش و اطمینان حاصل کنیم که همیشه در محدوده تعداد دکمه های جابجایی که ما داریم، باقی می ماند. بنابراین، بگذارید مقداری را که تصویب می شود را بچرخانیم و آن را به مقدار int بازیگران Mathf.Repeat بگذاریم و مقدار را به عقب برگردانیم. تکرار یک روش واقعا مفید است که به شما اجازه می دهد یک مقدار بر اساس طول آن حلقه کنید. بنابراین، اگر شما سعی کردید ارزش خارج از طیف وسیعی از یک آرایه را تعیین کنید، به جای این که بیرون بیاید، به صفر میرسد. اگر از صفر بیرون رفتید، به بالای طول مورد بازگشت می کردید. برای طول، ما به یک فیلد که هنوز برای ایجاد آن اشاره کردیم اشاره می کنیم، به نام difficultyGroup. ما تبدیل و تعداد فرزندانمان را خواهیم گرفت. اکنون، در بالای این، بیایید پیش برویم و این زمینه جدید را ایجاد کنیم. ما این گروه را تغییر می دهیم و گروه difficulty را نام می بریم. و اکنون، برای آزمایش این، بیایید خطایابی را وارد کنیم که ارزش ایجاد کرده است. بعدا میخواهیم دو فیلد دیگر ایجاد کنیم. از آنجا که ما به طور مستقیم به کلاس ورودی صحبت می کنیم، می خواهیم تاخیر بین هر بار که ما می بینیم اگر دکمه فشار داده شده است. به منظور انجام این کار، ما یک تاخیر کوچک را با دست انجام می دهیم، همانطور که ما در پنجره های قبلی انجام داده ایم. ما با ایجاد یک شناور به نام inputDay شروع خواهیم کرد. و ما این را به .3f تنظیم می کنیم. ما یک شناور خصوصی ایجاد خواهیم کرد و ما این تاخیر را فرا می گیریم. و ما این را صفر می کنیم. حالا، در بالای روش بروز رسانی ما، کد زیر را اضافه میکنیم:
.deltaTime; Next, we'll test if the delay is greater than the input delay. If it is, we're gonna change the difficulty. We'll start by taking the current value of the difficulty and calling it newDifficulty. And we'll set it to the existing difficulty value. Next, we're gonna wanna get a reference to the horizontal axis from the input class. Here, we'll create a variable called hDir, and we'll set it to equal the input class, GetAccess, and we'll look for the horizontal access. This is gonna return a value between negative one for left, or one for right, zero meaning nothing has changed. Here, we'll create a condition that tests the horizontal direction is greater than zero. If it is, we'll increase the newDifficulty value. Else, if the h direction is less than zero, we'll reduce the newDifficulty value by one. And finally, we're gonna test to see if the newDifficulty value does not equal the previous difficulty value. If it does, we're gonna set the difficulty to the new difficulty. And finally, we'll reset our delay to equal zero. Now, let's save our class and go back into unity. Let's select the DifficultyWindow and pass in the difficulty ToggleGroup to our Difficulty Group field. Now, if we run our game and go to the newDifficulty, if we hit right and left, you'll see in our console, it'll output the numbers one and two, based on the direction that we're going. Since we're not saving this value, it'll only stay floating between one and two, since that's where the default value was originally set. But the good news is that we've now learned how to directly capture input and next, we'll learn how to map it to the actual UI itself.

