I’m having a hell of a time these past few days trying to get it to work and the major problems are so follows:
-
GUIText only shows text when I place it on my background and not the lose collider, where the lives should go considering the only way to lose them is when the ball hits it.
-
Due to the above issue, I placed the GUIText on the background and tried to use a script to modify it. I found my code worked to modify the text, but had no idea how to reference the LoseCollider so I moved the code to there, but despite referencing the GUIText, it doesn’t alter the text. Even exposing it publically, it refuses to do so.
Here’s my code below, I’ve been searching for answers for the past two days and I think I’m onto something, but with so many similar questions being answered in different versions it’s impossible to know if it works or not. I’ll post both the LoseCollider and the Player Lives script I was using on the Background and the LevelManager for any suggestions of if that needs altering too and yet I know the code is out of date, but when I changed it, it messed up the LoseCollider and I couldn’t fix it no matter what:
LoseCollider:
using UnityEngine;
using System.Collections;
using System;
public class LoseCollider : MonoBehaviour {
private LevelManager levelManager;
public GUIText livesGui;
private int Lives;
void start() {
livesGui = GetComponent<GUIText>();
livesGui = FindObjectOfType<GUIText>();
Lives = 5;
}
void OnTriggerEnter2D(Collider2D trigger) {
}
void OnCollisionEnter2D(Collision2D collision){
levelManager = FindObjectOfType<LevelManager>();
levelManager.LoadLevel("Lose");
}
void update()
{
livesGui.text = "lives x " + Lives;
}
}
PlayerLivers:
using UnityEngine;
using System.Collections;
public class PlayerLives : MonoBehaviour {
public GUIText livesRemaining;
private LevelManager levelManager;
private LoseCollider loseCollider;
private int Lives;
void Start () {
levelManager = FindObjectOfType<LevelManager>();
loseCollider = FindObjectOfType<LoseCollider>();
livesRemaining = FindObjectOfType<GUIText>();
Lives = 5;
}
void Update () {
livesRemaining.text = "lives x " + Lives;
}
}
LevelManager:
using UnityEngine;
using System.Collections;
public class LevelManager : MonoBehaviour {
public void LoadLevel(string name){
Brick.breakableCount = 0;
Application.LoadLevel(name);
}
public void QuitRequest(){
Application.Quit();
}
public void LoadNextLevel() {
Brick.breakableCount = 0;
Application.LoadLevel(Application.loadedLevel + 1);
}
public void BrickDestroys()
{
if (Brick.breakableCount <= 0) {
LoadNextLevel();
}
}
}
As you can see I did do some research and using my own deduction to come up with certain ways of how to tackle it (had to look up how to activate the GUIText’s text) but I’ve now hit a brick wall. Any help would be appreciated Thanks.