【发布时间】:2016-05-05 07:11:03
【问题描述】:
我正在制作一个涂鸦跳跃游戏,现在我被卡住了。玩家一碰硬币就得到分数,我想打个高分,这样当它重新启动时,或者当你点击主菜单时,会有一个文字说高分和你的分数。我已经写好了文字。请帮助我!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public static GameManager instance = null;
public GameObject textscoreobject;
int score;
Text scoretext;
void Awake()
{
scoretext = textscoreobject.GetComponent<Text>();
scoretext.text = "Score: " + score.ToString ();
if (instance == null)
instance = this;
else if(instance != null)
Destroy(gameObject);
}
public void Collect(int passedvalue, GameObject passedobject)
{
Destroy (passedobject);
score = score + passedvalue;
scoretext.text = "Score: " + score.ToString ();
}
}
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public int value;
public float rotatespeed;
void Update ()
{
gameObject.transform.Rotate (Vector3.up * Time.deltaTime * rotatespeed);
}
void OnTriggerEnter()
{
GameManager.instance.Collect (value, gameObject);
}
}
这里是现在一些屏幕的代码! https://www.dropbox.com/s/90mf2esf4tqe7xh/Capture.PNG?dl=0 这里是高分需要显示的地方! 请帮帮我!
【问题讨论】:
-
什么不起作用?您在此处显示的代码的哪一部分与您的实际问题相关?
-
其实我展示的东西有效,我希望你帮我写代码来保存高分!
-
有太多可能的答案,而好的答案对于这种格式来说太长了。请添加详细信息以隔离可以在几段中回答的问题。