• We just launched and are currently in beta. Join us as we build and grow the community.

Creating Gameplay Controller

muttly105

Content Syndication Guru
M Rep
0
0
0
Rep
0
M Vouches
0
0
0
Vouches
0
Posts
156
Likes
119
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Operating System

Android

Now we will create the Gameplay Controller. This will be the game mechanics of the game. It will handle the flow of the game to make it playable. Create a GameObject then name it as Gameplay Controller. Then create a script and save it to Game Controllers folder as GameplayController.

Write these important variables to make the game work properly:
  1. public

    static

    GameplayController instance;

  2. public

    int

    score;
  3. public

    Text scoreText;
  4. public

    GameObject notification;

  5. private

    bool

    doubleBack;

Then write the rest of the codes
  1. void

    Awake(

    )

    {
  2. CreateInstance (

    )

    ;
  3. }

  4. // Use this for initialization
  5. void

    Start (

    )

    {
  6. if

    (

    GameController.

    instance

    !=

    null

    &&

    MusicController.

    instance

    !=

    null

    )

    {
  7. if

    (

    GameController.

    instance

    .

    isMusicOn

    )

    {
  8. MusicController.

    instance

    .

    PlayGameplaySound

    (

    )

    ;
  9. }

    else

    {
  10. MusicController.

    instance

    .

    StopAllSound

    (

    )

    ;
  11. }
  12. }
  13. InitialGameplayVariables (

    )

    ;
  14. }

  15. // Update is called once per frame
  16. void

    Update (

    )

    {
  17. UpdateGameplayController (

    )

    ;

  18. if

    (

    doubleBack ==

    true

    )

    {
  19. if

    (

    Input.

    GetKeyDown

    (

    KeyCode.

    Escape

    )

    )

    {
  20. SceneManager.

    LoadScene

    (

    "Main Menu"

    )

    ;
  21. }
  22. }

  23. if

    (

    Input.

    GetKeyDown

    (

    KeyCode.

    Escape

    )

    )

    {
  24. notification.

    SetActive

    (

    true

    )

    ;
  25. doubleBack =

    true

    ;
  26. StartCoroutine (

    ShowTimer (

    )

    )

    ;
  27. }
  28. }

  29. void

    CreateInstance(

    )

    {
  30. if

    (

    instance ==

    null

    )

    {
  31. instance =

    this

    ;
  32. }
  33. }

  34. void

    UpdateGameplayController(

    )

    {
  35. GameController.

    instance

    .

    currentScore

    =

    score;
  36. scoreText.

    text

    =

    score.

    ToString

    (

    )

    ;
  37. }

  38. void

    InitialGameplayVariables(

    )

    {
  39. GameController.

    instance

    .

    currentScore

    =

    0

    ;
  40. score =

    GameController.

    instance

    .

    currentScore

    ;
  41. scoreText.

    text

    =

    score.

    ToString

    (

    )

    ;
  42. }

  43. IEnumerator ShowTimer(

    )

    {
  44. yield

    return

    new

    WaitForSeconds (

    2f)

    ;
  45. doubleBack =

    false

    ;
  46. notification.

    SetActive

    (

    false

    )

    ;
  47. }

After creating the script attach it to the Gameplay Controller component. And then attach all the needed components in the Inspector of GameplayController script.
37_1.png


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

439,009

316,008

316,017

Top