In the world of Unity, there are two scenes that need to be controlled with a script in a native iOS app. Imagine having two buttons in the app - when the first button is clicked, it should display scene1, and when the second button is clicked, it should show scene2. I have come across a script for Android, but now I need to adapt it for iOS. Attached below is the script designed for Android:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.VR;
using System;
public class AnimatorScript : MonoBehaviour
{
public Animator animation;
AndroidJavaObject intent , currentActivity , extras;
bool hasExtra;
string arguments;
// Use this for initialization
void Start ()
{
try
{
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
intent = currentActivity.Call<AndroidJavaObject>("getIntent");
hasExtra = intent.Call<bool> ("hasExtra", "test_val");
Debug.Log(hasExtra);
Debug.Log("start");
}
catch(Exception e)
{
Debug.Log(e);
}
}
public void loadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
// Update is called once per frame
void Update ()
{
if (hasExtra)
{
Debug.Log("has extra");
extras = intent.Call<AndroidJavaObject>("getExtras");
arguments = extras.Call<string> ("getString", "test_val");
if(string.Equals(arguments,"scene1"))
{
animation.Play("dancing_warrior_sun-001");
}
if(string.Equals(arguments,"scene2"))
{
// animation.Play("seating_poses-001");
SceneManager.LoadScene(1);
}
else Debug.Log("No Animation Found");
Debug.Log(arguments);
}
else
{
Debug.Log("no extra");
}
}
}