Updating Placeskee ballMachine

We need to update and add some new functionalities to Placeskee ballMachine. Mostly, we will change the update function to respond to AppState.PlaceSkeeMachine, AppState.PlaceSkeeMachineComplete, and AppState.StartGame. We will also change our Options button by renaming it to MoveBtn and then making it change whether the user is moving the machine or not. Let's carry out these steps:

  1. Open up the Placeskee ballMachine.cs file and add the following line around line 28:
  1. Save the file and head back to Unity for a moment.
  2. Find skee|UI|OptionsBtn.
  3. Rename it to MoveBtn.
  4. Now, drag the object from the Hierarchy view to the Move Button field of the Placeskee ballMachine GameObject.

Now, we need to go back to Visual Studio and ensure that Placeskee ballMachine still has focus. We will change the Update() method by adding three new if statements.

Directly inside the function, before the existing code in the Update() method, add lines 74 to 101:

It's time for a quick rundown of the changes we made:

  • In the first if statement, we check to see whether the ApplicationManager has set the bool destroySkeeCollider to true, which means we are getting rid of the outer collider on the machine. If that bool is set to true in the application manager, then we destroy the collider attached to this GameObject.
  • The second if statement checks to see whether the AppState.PlaceSkeeMachineComplete is the current myAppState. If it is, we stop drawing the SpatialMapping visual mesh and attach a World Anchor to the object.
  • In the final if statement, we are repeating parts of the last two if statements and then setting our move button text to an empty string to make it go away. Then, we set the AppState to WaitForInput. There were scenarios where we would reach this state without having reached the previous if statements, so this is very bad, but there's a quick fix for that issue.

Now, in the OnInputClicked() function down at line 141, we need to change it so that the object will only accept input at certain times. In this case, the only time this object should react to a click at all is if the AppState has been set to PlaceSkeeMachine. Fortunately, this is rather effortless. We simply add an if statement to check whether the AppState of ApplicationManager is currently PlaceSkeeMachine. This should be the first code inside the method. Then, we add a } at the end:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.17.45