Why doesn't Google Play Game authorization work in Unity? - c#

I did everything right, I specified SHA1 in the Google API, Linked it all to Google Console, inserted resources and Web Client ID into Unity, but every time I try to log in, it writes "Canceled".
In LogCat I don't get errors, there are only:
*** [Play Games Plugin 0.11.01] 02.18.23 ERROR: Returning an error code
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
Google Play services out of date for iae.perfectray.dogs. Reqires 21300000 but found 212621032
Here is the authorization code:
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Auth : MonoBehaviour
{
// Start is called before the first frame update
public Text text;
void Start()
{
PlayGamesPlatform.Activate();
PlayGamesPlatform.DebugLogEnabled = true;
}
public void Authh()
{
PlayGamesPlatform.Instance.Authenticate(ProccessAuth);
}
internal void ProccessAuth(SignInStatus status)
{
if(status == SignInStatus.Success)
{
text.text = "Status: Succesfull";
}
else
{
text.text = "Status: " + status;
}
}
I've already tried everything, nothing works(

Related

Index was outside the bounds of the array. Login+<LoginPlayer>d__4.MoveNext () (at Assets/Login.cs:29)

I'm building a system in Unity that takes a register and login menu connected to a MySQL database through PHPMyAdmin, has users log in, then allows them to choose between playing two games. I've been getting this error since I linked the games and I can't figure out how to fix it. The register works fine, but it won't allow for log in.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Login : MonoBehaviour
{
public TMP_InputField nameField;
public TMP_InputField passwordField;
public Button submitButton;
public void CallLogin()
{
StartCoroutine(LoginPlayer());
}
IEnumerator LoginPlayer()
{
WWWForm form = new WWWForm();
form.AddField("name", nameField.text);
form.AddField("password", passwordField.text);
WWW www = new WWW("http://localhost/sqlconnect/login.php", form);
yield return www;
if (www.text[0] == '0')
{
dbmanager.username = nameField.text;
dbmanager.score = int.Parse(www.text.Split('\t')[1]);
UnityEngine.SceneManagement.SceneManager.LoadScene(0);
}
else
{
Debug.Log("User Login failed. Error #" + www.text);
}
}
public void VerifyInputs()
{
submitButton.interactable = (nameField.text.Length >= 8 && passwordField.text.Length >= 8);
}
}
I've been trying to figure out what happened for hours and need some extra insight, can anyone please help?

Generate new prefab using prefab after edit in runtime

I have simple script and work perfect, but only runing in Unity Editor. I Try build for mobile, not complete and error build. i using Unity 2019.3.4.
Is there a subtitute "using UnityEditor" for mobile script.
I need script for mobile. Any idea for running in mobile.
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Collections.Generic;
public class Prefabz : MonoBehaviour
{
public GameObject selObj;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
CreatePrefab();
}
}
void CreatePrefab()
{
//GameObject[] selObjs = Selection.gameObjects;
string charName = selObj.name;
// duplicate
GameObject newInstance = Instantiate(selObj);
newInstance.name = charName;
// now replace the prefab
string prefabPath = "Assets/trideeScript/" + charName + ".prefab";
var existingPrefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject));
if (existingPrefab != null)
{
PrefabUtility.ReplacePrefab(newInstance, existingPrefab, ReplacePrefabOptions.ReplaceNameBased);
}
else
{
PrefabUtility.CreatePrefab(prefabPath, newInstance);
}
// delete dupe
DestroyImmediate(newInstance);
Debug.Log("Prefab'd " + charName + "! \"" + prefabPath + "\"");
}
}
UnityEditor namespace is not supported on any platform, except actually Editor. That's why all editor scripts must be placed inside "Editor" folder, and that's why it's a good practice to keep any editor-related stuff inside pre-processor directives #if UNITY_EDITOR

My unity login with Firebase is not working

My register user is working perfectly, however when i try to log a user in i do not get any kind of message, successful login or failed login. I am trying to log my user in then move to my logged in screen. If anyone is able to see what it is i am doing wrong i would be very thankful!
I will provided my code below.
Thank you for your help!
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using System.Text.RegularExpressions;
using UnityEngine.SceneManagement;
using Firebase;
using Firebase.Auth;
public class Login : MonoBehaviour {
public GameObject email;
public GameObject password;
private string Email;
private string Password;
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
void Update () {
if (email.GetComponent<InputField>().isFocused){
password.GetComponent<InputField>().Select();
}
if (Password != ""&&Password != ""){
LoginButton();
}
Email = email.GetComponent<InputField>().text;
Password = password.GetComponent<InputField>().text;
}
public void LoginButton()
{
auth.SignInWithEmailAndPasswordAsync(Email, Password).ContinueWith(task => {
if (task.IsCanceled) {
Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
SceneManager.LoadScene("LoginScreen");
});
}
}
Replace ContinueWith with ContinueWithOnMainThread, I think you should be good. If not, make sure you've enabled email sign in in the Firebase console.
I suspect that everything's working as expected, but because you're using ContinueWith your SceneManager logic is happening off of the main thread. In the best case scenario, this just won't work. In the worst case, you might see a crash.
See my article on threading in Unity and my video on Authentication for more information.

Writing .txt file in android

I need help with a problem in our system. We are using unity and visual studio C# to create a mobile VR game using gaze controls only (no controller). We need to find a way to write debug logs into a text file and save to android internal storage. Thanks in advance for the help!!
That is our code below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine;
public class VRPlace : MonoBehaviour
{
...
void OnTriggerEnter(Collider other)
{
string path = "Assets/Resources/PlacesLog.txt";
StreamWriter testing = new StreamWriter(path, true);
if (other.gameObject.name == "Hospital")
{
GameObject otherObj = other.gameObject;
Debug.Log("Triggered to: " + otherObj);
}
testing.WriteLine(other.gameObject.name);
testing.Close();
}
}
here is a sample for saving a .txt file with StreamWriter.
class FileSaver
{
static void Main()
{
// Create a StreamWriter instance
StreamWriter writer = new
StreamWriter(Application.PersistentDataPath + "/droidlog.txt");
// This using statement will ensure the writer will be closed when no longer used
using(writer)
{
// Loop through the numbers from 1 to 20 and write them
for (int i = 1; i <= 20; i++)
{
writer.WriteLine(i);
}
}
}
}
this saves the numbers 1-20, you will want to fill in the blanks... good luck!

QR Code Scanner in Unity?

I am trying to get QRCode reader in unity that works on ios and Android.
Unity Zxing QR code scanner integration
Using above answer I Have added Vuforia (Working perfectly alone). then i also have added Zxing.unity.dll in plugins folder, then added this script to ARCamera in a scene.
using UnityEngine;
using System;
using System.Collections;
using Vuforia;
using System.Threading;
using ZXing;
using ZXing.QrCode;
using ZXing.Common;
[AddComponentMenu("System/VuforiaScanner")]
public class VuforiaScanner : MonoBehaviour
{
private bool cameraInitialized;
private BarcodeReader barCodeReader;
void Start()
{
barCodeReader = new BarcodeReader();
StartCoroutine(InitializeCamera());
}
private IEnumerator InitializeCamera()
{
// Waiting a little seem to avoid the Vuforia's crashes.
yield return new WaitForSeconds(1.25f);
var isFrameFormatSet = CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.RGB888, true);
Debug.Log(String.Format("FormatSet : {0}", isFrameFormatSet));
// Force autofocus.
var isAutoFocus = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
if (!isAutoFocus)
{
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_NORMAL);
}
Debug.Log(String.Format("AutoFocus : {0}", isAutoFocus));
cameraInitialized = true;
}
private void Update()
{
if (cameraInitialized)
{
try
{
var cameraFeed = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGB888);
if (cameraFeed == null)
{
return;
}
var data = barCodeReader.Decode(cameraFeed.Pixels, cameraFeed.BufferWidth, cameraFeed.BufferHeight, RGBLuminanceSource.BitmapFormat.RGB24);
if (data != null)
{
// QRCode detected.
Debug.Log(data.Text);
}
else
{
Debug.Log("No QR code detected !");
}
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
}
}
}
But it is still not detecting any QRCode. Is there any other way to do QRcode reading and writing except Zxing? or any working sample project you have?
I also tried to implement a QRCode Reader with Vuforia and XZing using almost the same code you used. For me it worked, but it took very very long to detect the QRCode.
When I used a Color32 array instead of cameraFeed.pixels it was much quicker:
GUI.DrawTexture(screenRect, webCamTexture, ScaleMode.ScaleToFit);
try
{
IBarcodeReader barcodeReader = new BarcodeReader();
var result = barcodeReader.Decode(webCamTexture.GetPixels32(),
webCamTexture.width, webCamTexture.height);
if (result != null)
{
Debug.Log("DECODED TEXT FROM QR: " + result.Text);
loadNewPoi(Convert.ToInt32(result.Text));
PlayerPrefs.SetInt("camera_enabled", Convert.ToInt32(false));
webCamTexture.Stop();
}
}
But in this example I was using a WebCamTexture instead of Vuforia.
Unluckily it isn't possible to get a Color32 array with GetPixels32() from the Vuforia camera.
Another option is to use the QRCodes as Image-Targets, but I have a lot of wrong detections doing this.
For me there is no fitting solution for XZing together with Vuforia at the moment.

Categories

Resources