0% found this document useful (0 votes)
60 views2 pages

App - Initialize: " - Curvature" " - Trimming"

This script initializes and manages the game UI, gameplay state, and advertisement integration. It activates and deactivates different UI elements based on whether the game is in the menu, playing, or over. It handles starting the game after a button click or rewarded ad is shown. It also loads the restart scene when restart is selected.

Uploaded by

Kodar Sticko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

App - Initialize: " - Curvature" " - Trimming"

This script initializes and manages the game UI, gameplay state, and advertisement integration. It activates and deactivates different UI elements based on whether the game is in the menu, playing, or over. It handles starting the game after a button click or rewarded ad is shown. It also loads the restart scene when restart is selected.

Uploaded by

Kodar Sticko
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System.

Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Advertisements;
using UnityEngine.UI;

public class App_Initialize : MonoBehaviour {

public GameObject inMenuUI;


public GameObject inGameUI;
public GameObject gameOverUI;
public GameObject adButton;
public GameObject restartButton;
public GameObject player;
private bool hasGameStarted = false;
private bool hasSeenRewardedAd = false;

void Awake() {
Shader.SetGlobalFloat("_Curvature", 2.0f);
Shader.SetGlobalFloat("_Trimming", 0.1f);
Application.targetFrameRate = 60;
}

void Start () {
player.GetComponent<Rigidbody>().constraints =
RigidbodyConstraints.FreezePosition;
inMenuUI.gameObject.SetActive(true);
inGameUI.gameObject.SetActive(false);
gameOverUI.gameObject.SetActive(false);
}

public void PlayButton() {


if (hasGameStarted == true) {
StartCoroutine(StartGame(1.0f));
} else {
StartCoroutine(StartGame(0.0f));
}
}

public void PauseGame() {


player.GetComponent<Rigidbody>().constraints =
RigidbodyConstraints.FreezePosition;
hasGameStarted = true;
inMenuUI.gameObject.SetActive(true);
inGameUI.gameObject.SetActive(false);
gameOverUI.gameObject.SetActive(false);
}

public void GameOver() {


player.GetComponent<Rigidbody>().constraints =
RigidbodyConstraints.FreezePosition;
hasGameStarted = true;
inMenuUI.gameObject.SetActive(false);
inGameUI.gameObject.SetActive(false);
gameOverUI.gameObject.SetActive(true);
if (hasSeenRewardedAd == true) {
adButton.GetComponent<Image>().color = new Color(1, 1, 1, 0.5f);
adButton.GetComponent<Button>().enabled = false;
adButton.GetComponent<Animator>().enabled = false;
restartButton.GetComponent<Animator>().enabled = true;
}
}

public void RestartGame() {


SceneManager.LoadScene(0); //loads whatver scene is at index 0 in build settings
}

public void ShowAd() {


if (Advertisement.IsReady("rewardedVideo")) {
var options = new ShowOptions { resultCallback = HandleShowResult };
Advertisement.Show("rewardedVideo", options);
}
}

private void HandleShowResult(ShowResult result) {


switch (result) {
case ShowResult.Finished:
Debug.Log("The ad was successfully shown.");
hasSeenRewardedAd = true;
StartCoroutine(StartGame(1.5f));
break;
case ShowResult.Skipped:
Debug.Log("The ad was skipped before reaching the end.");
break;
case ShowResult.Failed:
Debug.LogError("The ad failed to be shown.");
break;
}
}

IEnumerator StartGame(float waitTime) {


inMenuUI.gameObject.SetActive(false);
inGameUI.gameObject.SetActive(true);
gameOverUI.gameObject.SetActive(false);
yield return new WaitForSeconds(waitTime);
player.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
player.GetComponent<Rigidbody>().constraints =
RigidbodyConstraints.FreezePositionY;
}
}

You might also like