Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The audio sound is not off onclick in the same scene and it off 50% in second screen .... but i require to mute the audio in same screen with all audio mute #1

Open
ashwanidv100 opened this issue Feb 11, 2017 · 0 comments

Comments

@ashwanidv100
Copy link

ashwanidv100 commented Feb 11, 2017

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Volume : MonoBehaviour {

public Sprite VolumeOn, VolumeOff;
private SpriteRenderer spriteRenderer;

void Start () {
	spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
	SetVolume(PlayerPrefs.GetInt("volume", 50) != 50 ? false : true);
}

void Update () {
	if(isTouched()) {
		SetVolume(PlayerPrefs.GetInt("volume", 50) != 50 ? true : true);
	}
}

private void SetVolume(bool IsOn) {
	if(IsOn) {
		spriteRenderer.sprite = VolumeOn;
		PlayerPrefs.SetInt("volume", 50);
	} else {
		spriteRenderer.sprite = VolumeOff;
		PlayerPrefs.SetInt("volume", 0);
	}
}

public bool isTouched() {
	bool result = false;
	if(Input.touchCount == 1) {
		if(Input.touches[0].phase == TouchPhase.Ended) {
			Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
			Vector2 touchPos = new Vector2(wp.x, wp.y);
			if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(touchPos)) {
				result = true;
			}
		}
	}
	if(Input.GetMouseButtonUp(0)) {
		Vector3 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		Vector2 mousePos = new Vector2(wp.x, wp.y);
		if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(mousePos)) {
			result = true;
		}
	}
	return result;
}

}

@ashwanidv100 ashwanidv100 reopened this Oct 18, 2017
@ashwanidv100 ashwanidv100 changed the title The audio sound is not off onclick in the same scene and it off 50% in second screen .... but i require to mute the audio in same screen with all audio mute The audio sound is not off onclick in the same scene and it off 50% in second screen .... but i require to mute the audio in same screen with all audio mute -label:bug Oct 27, 2017
@ashwanidv100 ashwanidv100 changed the title The audio sound is not off onclick in the same scene and it off 50% in second screen .... but i require to mute the audio in same screen with all audio mute -label:bug The audio sound is not off onclick in the same scene and it off 50% in second screen .... but i require to mute the audio in same screen with all audio mute label:bug Oct 27, 2017
@ashwanidv100 ashwanidv100 changed the title The audio sound is not off onclick in the same scene and it off 50% in second screen .... but i require to mute the audio in same screen with all audio mute label:bug The audio sound is not off onclick in the same scene and it off 50% in second screen .... but i require to mute the audio in same screen with all audio mute Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant