Problem with Strings updatings on Gui
Hi i have problem with Strings In my "Game" they aren update correctly. Here is code and some snaps , And also the You Lost/You Lose text arent switching their's visibility to active from the sript... Debugs are working fine for me. Im a noobbut rly tried everyting to make it act like it should. funny Staff is whe i was using the same script ina 3d game it worked perfectly :S. Waiting for your's Respond.
using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic;
public class Gamemenager : MonoBehaviour { public int lifes = 3; public int bricks = 0; public int points = 0; public float resetDelay =1f ; public Text BallsCount; public Text Points; public GameObject Ball; public GameObject Roof; public GameObject Bonus; public GameObject YouWon; public GameObject YouLost; public List bricksPrefabs; public GameObject Paddle; public GameObject deathParticles; private Ball ball; public static Gamemenager instance = null; private GameObject clonePaddle; private GameObject cloneBall; public GameObject DamangedBrickRed;
// chceks is there allready eny instance startet if so it will destroy coppies
void Start()
{
if (instance == null)
instance = this;
else if (instance != null)
Destroy(gameObject);
Setup();
}
// Spawn map objects
public void Setup()
{
clonePaddle = Instantiate(Paddle, transform.position, Quaternion.identity) as GameObject;
clonePaddle.transform.SetParent(Roof.transform);
cloneBall = Instantiate(Ball, transform.position, Quaternion.identity) as GameObject;
cloneBall.transform.SetParent(Roof.transform);
RandomBlocks();
BallsCount.text = "Balls: " + lifes.ToString();
Points.text = "Points: " + points.ToString();
//ball = GameObject.Find("Ball").gameObject.GetComponent<Ball>();
}
// Chceks game over
public void ChceckGameOver()
{
if (bricks == 0)
{
YouWon.SetActive(true);
Time.timeScale = .20f;
Invoke("Reset", resetDelay);
}
if (lifes == 0)
{
Debug.Log("Koniec!");
YouLost.SetActive(true);
Time.timeScale = .20f;
Invoke("Reset", resetDelay);
}
}
private List<Vector2> vectors = new List<Vector2>();
// Random Bricks generator
private void RandomBlocks()
{
int n = 40;
bricks = n;
while (n > 0)
{
bool allow = true;
Vector2 vec = new Vector2(Random.Range(-400, 250) *1.6f, Random.Range(-100, 207) *1.6f);
foreach (Vector2 v in vectors)
{
if (v == vec)
{
allow = false;
}
}
if (allow == true)
{
vectors.Add(vec);
GameObject Go = Instantiate(bricksPrefabs[Random.Range(0, bricksPrefabs.Count)], vec, Quaternion.identity) as GameObject;
Go.transform.SetParent(Roof.transform);
n--;
}
}
foreach (Vector2 v in vectors)
Debug.Log(v);
Debug.Log("#############");
}
// Resets Level
void Reset()
{
Time.timeScale = 1f;
Application.LoadLevel(Application.loadedLevel);
}
//loose life
public void LoseLife()
{
lifes--;
BallsCount.text = "Balls: "+lifes.ToString();
Instantiate(deathParticles, clonePaddle.transform.position, Quaternion.identity);
Destroy(clonePaddle);
Invoke("SetupPaddle", resetDelay);
ChceckGameOver();
}
void SetupPaddle()
{
clonePaddle = Instantiate(Paddle, transform.position, Quaternion.identity) as GameObject;
clonePaddle.transform.SetParent(Roof.transform);
cloneBall = Instantiate(Ball, transform.position, Quaternion.identity) as GameObject;
cloneBall.transform.SetParent(Roof.transform);
}
public void DestroyBricksGreen()
{
Debug.Log("pkt");
bricks--;
points += 10;
Points.text = "Points: " + points.ToString();
ChceckGameOver();
}
public void DestroyBricksRed()
{
bricks--;
points += 20;
Points.text = "Points: " + points.ToString();
ChceckGameOver();
}
public void DestroyBricksBlue()
{
bricks--;
points += 5;
Points.text = "Points: " + points.ToString();
ChceckGameOver();
}
public void DamangeBricksRed()
{
points += 5;
Points.text = "Points: " + points.ToString();
}
public void BonusPoints()
{
points += 5;
Points.text = "Points: " + points.ToString();
}
public void Update()
{
Points.text = "Points: " + points.ToString();
BallsCount.text = "Balls: " + lifes.ToString();
}
}
][1]