我已经搜索了一段时间,无法找到并回答希望有人能帮助我!我想要做的是保存我的分数并将其转移到不同的场景。有了这个代码,我这里有我的错误:错误CS0029:无法将类型'int'隐式转换为'Score'
错误CS0029:Cannt隐式转换类型“诠释”到“分数”
我是相当新的统一的脚本为好。
这里有两个脚本我使用
脚本1个Score.cs
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
static public int score = 0;
static public int highScore = 0;
static Score instance;
static public void AddPoint() {
if(instance.run.dead)
return;
score++;
if(score > highScore) {
highScore = score;
}
}
Running run;
void Start() {
instance = this;
GameObject player_go = GameObject.FindGameObjectWithTag("Player");
if (player_go == null) {
Debug.LogError("could not find an object with tag 'Player'.");
}
run = player_go.GetComponent<Running>();
score = 0;
}
void OnDestroy() {
PlayerPrefs.SetInt ("score", score);
}
void Update() {
guiText.text = "Score: " + score;
}
}
和第二个脚本得到它到其他场景
using UnityEngine;
using System.Collections;
public class GetScore : MonoBehaviour {
Score score;
// Use this for initialization
void Start() {
score = PlayerPrefs.GetInt ("score");
}
// Update is called once per frame
void Update() {
guiText.text = "Score: " + score;
}
}
非常感谢所有帮助!
不能在代码片段工具运行C#代码。这是为JavaScript,HTML和CSS。 – 2014-09-25 07:32:28
是的,请不要将Stack Snippet用于非JS/HTML/CSS代码,我已将其删除。 – 2014-09-25 07:33:57