Witam. Jestem na tej stronie nowy i założyłem konto specjalnie w celu rozwiązania tego problemu. Dopiero zaczynam zabawę z programowaniem w unity(podstawy podstaw mam tam jakoś ogarnięte). Mam problem z wyświetleniem dystansu na ekranie jaki gracz(w tym przypadku kulka) obecnie przebył od początku gry(jest to gra typu Endless runer na Androida). Oto kod:
using UnityEngine;
using System.Collections;
public class Ruch : MonoBehaviour {
public float moveSpeed = 5.0f;
public float drag = 0.5f;
public float terminalRotationSpeed = 25.0f;
private Rigidbody rb;
private bool isDead = false;
Vector3 pozycja;
public float poz;
private void Start()
{
rb = GetComponent<Rigidbody> ();
rb.maxAngularVelocity = terminalRotationSpeed;
rb.drag = drag;
}
public void Update()
{
pozycja = transform.position;
poz = pozycja.x;
Debug.Log (pozycja.x);
}
public void Pkt ()
{
GetComponent<Score> ().Update (poz);
}
Oraz 2 kod z którym próbuje się skomunikować i wysłać pozycje po X aby skrypt przeliczył to na punkty i wyświetlił na ekranie.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Score : MonoBehaviour {
private float score = 0.0f;
private bool isDead = false;
public Text scoreText;
public DeathMenu deathMenu;
void Start () {
}
public void Update (float pktt) {
if (isDead)
return;
score = score + pktt;
scoreText.text = ((int)score).ToString ();
}
Proszę o pomoc.