- Home /
Sending Variable to Highscore Server results in 0.
Hello everybody,
In the last few hours I tried to make a little highscore for my test Scene, but it didn't work. I want to send the Variable 'elapsedTime' to my Highscore Database, but I always get a '0' as score. Any knows what I'm doing wrong? Here are the scripts :
TimerStart :
using UnityEngine;
using System.Collections;
public class TimerStart: MonoBehaviour
{
public float startTime;
public float elapsedTime;
void Awake(){
startTime = 0;
}
void Update () {
if (startTime > 0)
{
elapsedTime = Time.time - startTime;
}
}
void OnTriggerEnter()
{
startTime = Time.time;
}
void OnTriggerExit(){
//startTime = 0;
}
public void killTimer()
{
startTime = 0;
}
void OnGUI(){
GUI.Box(new Rect (10,40,300,25), new GUIContent("Elapsed Time : " + elapsedTime.ToString()));
}
}
TimerStop :
using UnityEngine;
using System.Collections;
class TimerStop : MonoBehaviour
{
public string ScoreSend;
void OnTriggerEnter()
{
TimerStart finaltime = gameObject.GetComponent<TimerStart>();
ScoreSend = finaltime.elapsedTime.ToString();
Debug.Log(ScoreSend);
}
}
Highscore Sender :
using UnityEngine;
using System.Collections;
public class SendHighScore : MonoBehaviour
{
string username = "Name";
bool finished = false;
void OnGUI()
{
username = GUI.TextField (new Rect (140, 70, 120, 20), username);
if(finished)
{
if (GUI.Button (new Rect (10,80,100,50), "Send Highscore"))
{
TimerStop ScoreRecv = gameObject.GetComponent<TimerStop>();
var ScoreSend = ScoreRecv.ScoreSend;
HighscoreSaver.postScore(username, ScoreSend + "", this);
}
}
}
void OnTriggerEnter()
{
finished = true;
}
}
Greetz, ITGeist.
Comment
What happens if you edit
var ScoreSend = ScoreRecv.ScoreSend;
to
String ScoreSend = ScoreRecv.ScoreSend;
?
Your answer
Follow this Question
Related Questions
Change main Camera to another camera with a Trigger then back with a Timer. 1 Answer
Timer that can be accessed in multiple scenes 1 Answer
Sprinting script, timer? 0 Answers
Highscore won't save 3 Answers
UI Problem for Game 1 Answer