Time for action — creating the activate layer method

The next method will activate/deactivate layers, depending on the game mode we give in as the parameter.

  1. Add a new method called ActivateLayer to the game class. As a parameter, it will take the game mode as an INT value.
    Method ActivateLayer:Int(mode:Int)
    Deactivate ALL layers.
    layerBackground.SetActive(False)
    layerGame.SetActive(False)
    layerGFX.SetActive(False)
    layerGameOver.SetActive(False)
    layerMenu.SetActive(False)
    layerScore.SetActive(False)
    layerTitle.SetActive(False)
    
  2. Start a Select statement with the variable mode as the expression.
    Select mode
    
  3. Check against the gmPlay constant. If it's true, activate the background, game, and GFX layers.
    Case gmPlay
    layerBackground.SetActive(True)
    layerGame.SetActive(True)
    layerGFX.SetActive(True)
    
  4. Check against the gmGameOver constant. If it's true, activate the background, game, GFX, and the GameOver layers.
    Case gmGameOver
    layerBackground.SetActive(True)
    layerGame.SetActive(True)
    layerGFX.SetActive(True)
    layerGameOver.SetActive(True)
    
  5. If the check against the gmMenu constant is true, activate the menu layer.
    Case gmMenu
    layerMenu.SetActive(True)
    
  6. Check against the gmScore constant and activate the score layer if it's true.
    Case gmScore
    layerScore.SetActive(True)
    
  7. And last but not least, check against the gmTitle constant. Again, if it's true, activate the title layer.
    Case gmTitle
    layerTitle.SetActive(True)
    
  8. Close the Select statement and the method.
    End
    Return 0
    End
    

What just happened?

You have created a method that lets you switch layers, depending on the game mode. If you need to add more layers, then don't forget to add a switch for them here, too.

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

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