(Unity UWP) Application.OpenURL() with query string crash the game - c#

Application.OpenURL() crash the game when the url have query string.
unity version: 2021.3.3f1
platform: UWP
After build and run.
When I click btn2, the app open the google search page, and the game crashed.
But btn1 can open the google homepage properly without crashing the game.
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour{
public Button btn1;
public Button btn2;
void Start(){
btn1.onClick.AddListener(() =>{
Application.OpenURL("https://www.google.com/");// this can run properly
});
btn2.onClick.AddListener(() =>{
Application.OpenURL("https://www.google.com/search?q=unity");// this will crash the game
});
}
void Update(){}
}
build settings:
build settings

Related

SceneManager.LoadScene not loading scenes

using UnityEngine;
using UnityEngine.SceneManagement;
public class Buttons : MonoBehaviour
{
public void loadLevel()
{
SceneManager.LoadScene("Level");
}
}
This is the code I am using, loadLevel() is supposed to load the scene Level when a button is clicked, this should be simple and I am not sure what is going wrong.
Thanks in advance!
I guess you haven't added the scene "Level" in Build Settings (menu "File"-"Build Settings"). If it isn't in the build it can't be opened by LoadScene.
To add a scene you can either open it in the editor and then click on the "Add Open Scenes" button, or you can simply drag-and-drop the scene file from the Project-window to the "Scenes In Build".

Unity - opening and closing animation with key binding

I'm making an inventory menu that will be accessed via a key binding (I). When the keybinding is clicked then play the animation which brings in the menu, if the keybind is clicked again then it should close the menu. Not sure where I'm going wrong here.
I've attached the animation controller to the UI.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShowInventory : MonoBehaviour {
public Animator animator;
// Update is called once per frame
void Update() {
if (Input.GetKeyDown(KeyCode.I)) {
animator.SetBool("isOpen", true);
}
}
}
As well as the code, you must also make sure your state machine in the Animator Controller asset is set up properly too. Check out this tutorial if you haven't already: https://unity3d.com/learn/tutorials/topics/animation/animator-controller

Unity Scripting Main Menu Not Working? Don't Know Why?

I made a main menu in unity so now I'm down to the scripting. I have tried the mouseup / mousedown functions but nothing is wrong with my code but it won't work period no debug logs not errors just plain nothing.
Here's my C# Script to change levels.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour {
public bool Start;
public bool Quit;
void OnMouseUp(){
if(Start)
{
SceneManager.LoadScene(1);
}
if (Quit)
{
Application.Quit();
}
}
}
This is very simple but I still don't see why it isn't working.
Try OnMouseDown
As an event needs to happen first. So the player presses down then upon release the mouse button is up, you need that first click. hope that helps.
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
Make sure that you added the script to a gameobject inside your scene. Also make sure that Start or Quit are set to true.

UWP Window hangs with Monogame

I just tried to create a new UWP App referencing: MonoGame.Framework.WindowsUniversal 3.6.0.1625, and Targeting Windows 10 Creators Update (10.0; Build 15063).
I think I did everything right to "bootstrap" a : Game from the SwapChainPanel:
I put <SwapChainPanel x:Name="swapChainPanel" /> in my Page
I put this in codebehind:
public sealed partial class MainPage : Page
{
readonly Game1 _game;
public MainPage()
{
this.InitializeComponent();
// Create the game.
var launchArguments = string.Empty;
_game = MonoGame.Framework.XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, swapChainPanel);
_game.Run();
}
}
And my Game1 : Game is just the same as Monogame templates.
When I start the application, there are no exceptions and the whole window hangs on the "UWP SplashScreen" (when it shows you the icon of your app) and nothing happens. My Draw method just clears the screen with red, just to see it working, but it doesn't.
Am I missing something?
I attached a very simple project to show that.
Solved, the problem was calling: _game.Run();.
By reading the source code on Github, I saw that the method:
static public T Create(string launchParameters, CoreWindow window, SwapChainPanel swapChainPanel)
already called Run:
// Start running the game.
game.Run(GameRunBehavior.Asynchronous);
By removing my call to the Run method, everything worked.

How can I properly load my scene from another with a button click

I have 2 scenes, 'scene1' and 'scene2', first, i had to switch from scene1 to scene2, it worked perfectly by adding 'Load Level On Click' to the button in scene1 (see it here)
Now from scene2 to scene1, this time by clicking on an UI Button on scene2, i'm using OnClick() and a script called 'LoadScene' (see it here),
here is my simple script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class LoadScene : MonoBehaviour {
void Start()
{
}
void Update()
{
}
public void Load () {
SceneManager.LoadScene("scene1");
}
}
Now, the problem is when i click the button (in scene2) to switch to scene1, it works but i lose a lot of elements on the scene1 like buttons and images.
I don't really know where does the problem come from !! Is there something to add to my script so i can load my scene correctly?

Categories