【发布时间】:2013-12-26 16:16:17
【问题描述】:
是否可以从 Eclipse 中的统一游戏中访问变量(例如高分)? 变量存储在统一脚本中,如下所示:
using Assets.Scripts.Events;
using Assets.Scripts.Utils;
using UnityEngine;
namespace Assets.Scripts
{
public class ScoreManager : CommandMonoBehaviour
{
public int Score;
public void Start()
{
Subscribe(GameEvents.BasketGotMovingObject, OnBasketGotMovingObject);
}
private void OnBasketGotMovingObject(GameEventArgs<MovingObject> args)
{
Score = Mathf.Max(0, Score + args.Value.BonusPoints);
GameEvents.ScoreUpdated.Publish(new GameEventArgs<int>(Score));
}
}
}
该项目已通过 Unity IDE 导出到“Google Android 项目”。
导出项目中的onCreate函数如下所示:
protected void onCreate (Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().takeSurface(null);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
getWindow().setFormat(PixelFormat.RGB_565);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
setContentView(playerView);
playerView.requestFocus();
}
只有一个“UnityPlayer”。 如何访问“int Score”等脚本变量?
【问题讨论】:
-
标签 unity 用于 Microsoft Unity。请不要滥用它。
标签: android eclipse unity3d unityscript