【发布时间】:2019-01-08 06:03:53
【问题描述】:
Unity 中的两个场景。必须在本机 iOS 应用程序中编写用于控制统一场景(2)的脚本,假设当我单击第一个按钮时本机应用程序中的 2 个按钮必须显示场景 1 和场景 2 的第二个按钮,就像这样。我找到了一个适用于 android 的脚本,但需要为 iOS 编写它。 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");
}
}
}
【问题讨论】:
标签: javascript c# ios unity3d