Able101

Hop Hop - Unity Game Template - New Trending Game

by Able101

Hop Hop - Unity Game Template - New Trending Game Android

Screenshots

Hop Hop - Unity Game Template - New Trending Game Android

Specification

How to Use

Sample Code

using UnityEngine; using System.Collections; using UnityEngine.UI; // <summary> /// Audio manager : Helps in managing audio in the game /// Script used in : Unity Editor -> Hierarchy Panel -> MANAGERS -> AUDIO MANAGER /// </summary> public class AudioManager : MonoBehaviour { #region: PUBLIC VARIABLES public static AudioManager instance; // used to invoke methods of this class from other scripts public AudioClip jumpSound; // player jump sound public AudioClip explode; // explosion sound when player dies public AudioClip gatesOpen; // gates opening sound public AudioClip powerUp; // powerup sound when player collects mushroom public AudioClip splash; // splash sound when player falls in river public GameObject bgMusic; // background music public Sprite imgSoundOn,imgSoundOff; // sound on and off images public Sprite imgMusicOn,imgMusicOff; // music on and off images public bool soundOn; // to check if sound is on or off #endregion #region: PRIVATE VARIABLES Image imgBtnMusic,imgBtnSound; // images of sound and music buttons #endregion #region: LIFECYCLE METHODS // Use this for initialization void Start () { // make the AudioManager instance if(instance == null) // this instance will be called from other scripts instance = this; // get references to sound and music button images imgBtnMusic = GameObject.Find("btn_Toggle_Music").GetComponent<Image>(); imgBtnSound = GameObject.Find("btn_Toggle_Sound").GetComponent<Image>(); // check if background music should be played or not if(PlayerPrefs.GetString("Music") == "On") { bgMusic.SetActive(true); imgBtnMusic.sprite = imgMusicOn; } else { bgMusic.SetActive(false); imgBtnMusic.sprite = imgMusicOff; } // check if sound effects should be played or not if(PlayerPrefs.GetString("Sound") == "On") { sound imgBtnSound.sprite = imgSoundOn; } else { sound imgBtnSound.sprite = imgSoundOff; } } #endregion #region: PUBLIC METHODS /// <summary> /// Toggles the background music /// </summary> public void ToggleBGMusic() { if(bgMusic.activeSelf == true) { bgMusic.SetActive(false); imgBtnMusic.sprite = imgMusicOff; PlayerPrefs.SetString("Music","Off"); } else { bgMusic.SetActive(true); imgBtnMusic.sprite = imgMusicOn; PlayerPrefs.SetString("Music","On"); } } /// <summary> /// Toggles the sound effects /// </summary> public void ToggleSound() { if(PlayerPrefs.GetString("Sound") == "On") { PlayerPrefs.SetString("Sound","Off"); imgBtnSound.sprite = imgSoundOff; sound } else { PlayerPrefs.SetString("Sound","On"); imgBtnSound.sprite = imgSoundOn; sound } } /// <summary> /// Play the jump sound /// </summary> public void JumpSound() { if(soundOn) AudioSource.PlayClipAtPoint(jumpSound,transform.position); } /// <summary> /// Play the player explosion sound /// </summary> public void Explode() { if(soundOn) AudioSource.PlayClipAtPoint(explode,transform.position); } /// <summary> /// Play the player splash sound /// </summary> public void Splash() { if(soundOn) AudioSource.PlayClipAtPoint(splash,transform.position); } /// <summary> /// Play the power up sound /// </summary> public void PowerUp() { if(soundOn) AudioSource.PlayClipAtPoint(powerUp,transform.position); } /// <summary> /// Play the gates open sound /// </summary> public void GatesOpen() { if(soundOn) AudioSource.PlayClipAtPoint(gatesOpen,transform.position); } #endregion }

Video

Comments (0)

  • {{com.username}}
    {{com.username}}
    Buyer
    Seller

    {{com.username}}

    {{com.ctime}}

    {{com.content}}

    • {{com2.username}}
      {{com2.username}}
      Buyer
      Seller

      {{com2.username}}

      {{com2.ctime}}

      {{com2.content}}