07 Fatih Demirel: Code Prototypes - LordMrMittens/Bit-London GitHub Wiki

Quiz Manager

Quiz Manager works with multiple scripts (AnswerScript and QuestionsAndAnswers). QuestionsAndAnswers script keeps the quiz questions and four different answers in array which can be change in Unity Inspector. AnswerScript script has a boolen that controls the answer if they are correct. Quiz Manager gets the all information from the AnswerScript and QuestionsAndAnswers then generate's question as well as sets answer. If players choose the correct answer, script will add one point which is a score system for the player. If players choose the wrong answer, script will not add one point and generate new question for the player. QuizSystem QuizSystem

Dialog System

The UI was set up with text and a "continue" button. Creating a public string array main sentences, which as the name implies, will hold all the sentences that make up the game's dialogue. After that, a private integer variable was created, which is called index. Making typing effects made by coroutines called "type" Coroutines are acts with functions, but the code inside them does not run immediately, as in yield return new WaitForSeconds(f). All codes that come after this code will be delayed by f amounts. A text.Display was added inside the coroutine. Thus, in-game texts from the Unity Inspector were made changeable. Finally, the continue button has been added to move on to the next sentence. The if else condition is created so that the "Continue" button waits for the sentences to finish. DialogSystem

Player Movement

This script lets you choose the destination point on the NavMesh by clicking the mouse on the object’s surface. The position of the click is determined by a raycast, rather like pointing a laser beam at the object to see where it hits. Since the GetComponent function is fairly slow to execute, the script stores its result in a variable during the Start function rather than call it repeatedly in Update. PlayerMovement

NPC Movement

The ideal sequence of patrol points will depend on the way you want the NPCs to behave. The patrol points are supplied to the script using a public array of Transforms. This array can be assigned from the inspector using GameObjects to mark the points’ positions. The GotoNextPoint function sets the destination point for the agent and then selects the new destination that will be used on the next call. As it stands, the code cycles through the points in the sequence they occur in the array but you can easily modify this, say by using Random.Range to choose an array index at random. In the Update function, the script checks how close the agent is to the destination using the remainingDistance property. When this distance is very small, a call to GotoNextPoint is made to start the next leg of the patrol. NPCMovement

Scene Switch

Scene transition was set up using an empty object with a box collider. The box collider "IsTrigger" has to be turned on for the player to interact. When the player gets inside the Box collider, the box collider triggers the boolean and activates the UI system. The UI system uses Unity's SceneManagement which can easily set enabling and disabling the UI system. SceneSwitch