我试图从统一3D中的javascript访问C#静态变量。我如何实现它?我想得到我在javascript中使用它的分数。
Score.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Score : MonoBehaviour {
public Text txt;
public static int score;
public GameObject gameobj;
void Start () {
txt = gameobj.GetComponent<Text>();
txt.text = "Score : " + score;
}
void Update () {
txt = gameobj.GetComponent<Text> ();
txt.text = "Score : " + score;
score = score + 1;
}
int GetScore(){
return score;
}
}
Collide.js
#pragma strict
function OnTriggerEnter(otherObj: Collider){
var scoreScript : Score;
scoreScript = GetComponent("Score");
int score = scoreScript.GetScore();
if (otherObj.tag == "Wall"){
Debug.Log(score);
Application.LoadLevel(2);
}
else if (otherObj.tag == "End"){
Application.LoadLevel(6);
}
}
答案 0 :(得分:0)
让我告诉你答案: