Unity中的两个场景。必须编写一个脚本来控制本机iOS应用程序中的统一场景(2),假设当我单击第一个按钮时,本机应用程序中的两个按钮必须像这样显示scene1和scene2的第二个按钮。我找到了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");
}
}
}
答案 0 :(得分:0)
Building an application with a native plugin for iOS
您可以遵循官方文档,在iOS中使用 UnitySendMessage 在Unity上调用场景控制脚本。
答案 1 :(得分:0)
您可以通过两种方式更改/切换场景
1)在UI的“ Unity place”按钮中,如下编写用于场景更改的脚本,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuActions : MonoBehaviour {
public void MENU_ACTION_NextButton(string sceneName)
{
Application.LoadLevel(sceneName);
}
}
将此脚本拖到主摄像机并单击按钮,在检查器底部单击以添加此主摄像机并命名您需要更改的场景名称。对具有相同脚本的场景2进行此操作并命名该场景。
2)如果您的本机应用程序中有按钮,则按如下所示编写脚本,并尝试为无效更新编写脚本,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using UnityEngine.SceneManagement;
public class SceneChanger : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//SceneManager.LoadScene(scene);
// try your script................
}
public void ChangeScene( string scene ) {
// Application.LoadLevel(scene);
SceneManager.LoadScene(scene);
}
}
希望这会为您提供概念。