Blank screen in game after automatic keypad lock in nokia S40 - nokia

After the automatic keypad lock, when I unlock it, there appears a blank white screen and after 3-4 seconds, the game field appears. Any ideas, how to avoid this behaviour? I want that the game canvas should be immediately displayed after the unlock.
Update:
Here is my startApp method:
public void startApp() {
start();
}
public void start() {
instance = this;
display = Display.getDisplay(this);
display.setCurrent(myGame);
}

Related

How to interact with Canvas through the center of the screen when the cursor is in a locked state in Unity3d?

I tried several ways, but none of them looked like the right solution.
One solution that only works for Windows and only in full screen mode. However, this solution does not work well and looks very wrong:
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int SetCursorPos ( int x , int y );
void SetCursorPositionToCenter()
{
  SetCursorPos(Screen.width/2, Screen.height/2);
}
I also tried to override the BaseInput class. This script is needed so that Input does not come from the mouse, but through the center of the screen. However, when moving the cursor to the blocked state, the BaseInput override is ignored. I assume that this is due to the fact that this function is not called at all when the cursor is put into the locked state.
public class MyInput : BaseInput {
  public override Vector2 mousePosition{
    get { return Camera.main.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); }
  }
  public void Start(){
    GetComponent<StandaloneInputModule>().inputOverride = this;
  }
}
Is it possible to interact with Canvas through the center of the screen when the cursor is locked? It is important that all Canvas events are handled.

Unity, I have problem with DontDestroyOnLoad to keep tracking in different scence

im new in unity and i have a problem
I am making a game that have 2 scence(Main Menu Scence and Game Scence), i put my music on Main Menu scence. I make a empty game object and i attach audio source there(music) , and i also attach script like this :
First script
public static KeepTheMusicOn Instance;
void Awake()
{
if (!Instance)
Instance = this;
else
Destroy(this.gameObject);
DontDestroyOnLoad(this.gameObject);
}
With that script i can keep music play in second scence wihtout restart the music, and in the main menu scence i have settings that have button to mute the music , the button will run my second script .
Second Script:
public AudioSource mainMusic;
public void Update()
{
DontDestroyOnLoad(mainMusic);
}
public void MusicOnOff()
{
if (mainMusic.isPlaying)
{
mainMusic.Pause();
}
else
{
mainMusic.UnPause();
}
}
My problem is when i start the game so im in my main menu scence i can mute the music with the button, but when i go to game scence and i back to menu, the button dont do anything.
So that is my problem, i hope anyone can help me. Sorry for my bad english.
Sounds like when switching scenes you destroy the button. When you them go back to the main menu you destroy the duplicate instance of your audio controller thing => references configured in the Button are lost.
In your case since you use a public Singleton anyway you could as well (ab)use it and put a component on the Button itself instead (thus the reference can not get lost) and do something like e.g.
[RequireComponent(typeof(Button))]
public class MusicButton : MonoBehaviour
{
[SerializeField] private Button button;
private void Awake()
{
if(!button) button = GetComponemt<Button>();
// dynamically add the callback
// it won't appear in the editor but get called in onClick
button.onClick.AddListener(OnClicked);
}
private void OnClicked()
{
KeepTheMusicOn.Instance.MusicOnOff();
}
}
If you prefer seeing it in the editor you can ofcourse as well rove it from Awake, make the OnClicked public and reference it in the button's onClick event manually.

Unity 5: Game view - Run Time - SpaceBar Causing Issue

Game View- Camera Display
When I click the Space Bar for the player to jump, the Display drop down menu pops up and the player doesn't jump. However, the player can move upon all key presses.
Here's the information that I have:
1) Everything worked and functioned properly.
2) I added a health bar to my boss.
3) I created a second canvas (First canvas was for my Player's HP).
4) I made the Boss HP bar render mode: World Space.
5) I attached the canvas to the boss controller in the hierarchy as a child.
6) The code I use for Player Jump is Input.GetKeyDown(KeyCode.Space).
7) The mouse curser is inside the Game View whilst testing the SpaceBar Jump.
8) I'm developing in Unity 2018 5.3 2D mode.
Official Question('s):
1) Why does the Spacebar causing the camera display drop menu to appear?
2) How do I fix this?
Edit / Additional Content:
Here's my Jump script
public float jump1 = 5.0f;
private bool onGround;
//private bool dblJump; //Not implemented yet
public Rigidbody player;
void Start () {
player = GetComponent<Rigidbody>();
onGround = true;
}
// Update is called once per frame
void Update () {
if (onGround == true) {
if (Input.GetKeyDown(KeyCode.LeftShift))// KeyCode.Space
{
player.velocity = new Vector3(0, jump1, 0);
onGround = false;
// Debug.Log("The onGround is False");
}
}
}
Keep in mind that I have temporarily changed my jump to LeftShift. However, my problem persist with the space bar, even when I click it with left shift as my jump. SpaceBar seems to summon the drop down menu for the camera display. (I can't seem to catch the drop down menu with a screen shot because it goes away upon a click)
Also Note - I'm inside a class called PlayerJump : MonoBehavior.
It seems like it's a known issue with some versions of Unity 5.3, I have a few solutions you can try :
Drag you game window somewhere else in the editor
Enable the "Maximise on play" button
Attach this script to your drop-down element :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class DropdownScript : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {
void Start()
{
dropDown = GetComponent<Dropdown>();
dropDown.interactable = false;
}
public void OnPointerEnter(PointerEventData ped)
{
dropDown.interactable = true;
}
public void OnPointerExit(PointerEventData ped)
{
dropDown.interactable = false;
}
}
Otherwise update you Unity version if it's not the latest release? I am not experiencing this issue but many other users are apparently.

How to prevent mouse clicks from passing through GUI controls and playing animation in Unity3D [duplicate]

This question already has answers here:
Detect mouse clicked on GUI
(3 answers)
Closed 4 years ago.
Description
Hi Guys need your help I faced problems with mouse clicks which pass through UI panel in Unity, that is, I have created pause menu and when I click Resume button, the game gets unpaused and the player plays Attack animation which is undesirable.What I want is when I click Resume button, Attack animation should not be played. The same problem if I just click on panel not necessarily a button and the more I click on UI panel the more Attack animation is played after I exit pause menu. Moreover, I have searched for solutions to this issue and was suggeted to use event system and event triggers but since my knowledge of Unity is at beginner level I could not properly implement it. Please guys help and sorry for my English if it is not clear)) Here is the code that I use:
The code:
using UnityEngine;
using UnityEngine.EventSystems;
public class PauseMenu : MonoBehaviour {
public static bool IsPaused = false;
public GameObject pauseMenuUI;
public GameObject Player;
private bool state;
private void Update() {
//When Escape button is clicked, the game has to freeze and pause menu has to pop up
if (Input.GetKeyDown(KeyCode.Escape)) {
if (IsPaused) {
Resume();
}
else {
Pause();
}
}
}
//Code for Resume button
public void Resume() {
//I was suggested to use event system but no result Attack animation still plays once I exit pause menu
if (EventSystem.current.IsPointerOverGameObject()) {
Player.GetComponent<Animator>().ResetTrigger("Attack");
}
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
IsPaused = false;
}
//this method is responsible for freezing the game and showing UI panel
private void Pause() {
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
IsPaused = true;
}
//The code for Quit button
public void QuitGame() {
Application.Quit();
}
}
Im not sure if i understood your problem, but it sounds like somewhere in your code you start an attack when the player does a left click.
Now your problem is that this code is also executed when the player clicks on a UI element, for example in this case the Resume button?
You tried to fix this problem, by resetting the attack trigger of the animator, i think it would be a better solution to prevent the attack from starting instead of trying to reset it later.
EventSystem.current.IsPointerOverGameObject() returns true if the mouse is over an UI element.
So you can use it to modify your code where you start your attack:
... add this check in your code where you want to start the attack
if(EventSystem.current.IsPointerOverGameObject() == false)
{
// add your code to start your attack
}
...
Now your attack will only start if you are not over a UI element

Loader during Unity IAP Callback

I want to put loader in between dialog boxes come up for the purchase. What is the way for this?
Because when game player press Buy button, he should require to wait for 5 to 10 second depends on internet speed and server response and this process happed 2 to 3 times because multiple dialogs come up within screen.
So in this case, may be player can leave the screen. I want to put the loader so that game player realise that some processing is running in background, he required to wait for some time.
At present I was following completely this code for Unity IAP setup.
Integrating Unity IAP In Your Game
I assume this is for mobile platform but even if its not still the following can be considered:
Simple solution is to create a full screen Image (UI/Panel) object in your UI to block clicks. I would use Animator component (with triggers) to display this panel in front of other UI when there is a background process running.
public class Loader : MonoBehaviour
{
public static Loader Instance;
Animator m_Animator;
public bool Loading {get; private set;}
void Awake()
{
Instance = this; // However make sure there is only one object containing this script in the scene all time.
}
void Start()
{
//This gets the Animator, which should be attached to the GameObject you are intending to animate.
m_Animator = gameObject.GetComponent<Animator>();
Loading = false;
}
public void Show()
{
Loading = true;
m_Animator.SetBool("Loading", Loading); // this will show the panel.
}
public void Hide()
{
Loading = false;
m_Animator.SetBool("Loading", Loading); // this will hide the panel.
}
}
Then in any script which manipulates UI:
public void BuyButtonClicked()
{
Loader.Instance.Show();
// process time taking stuff
Loader.Instance.Hide();
}
You can also create any kind of loading animation as child of panel object using simple images and animation tool inside Unity (for example rotating animation (use fidget spinner, its cool)).
And in case of Android where user have option to leave screen by pressing OS back button you can prevent going back by checking if any loading is in progress by following example:
// code for back button
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
BackButtonPressed();
}
}
void BackButtonPressed()
{
if(Loader.Instance.Loading)
return;
// use back button event. (For example to leave screen)
}
Hope this helps ;)