Hi guys i was wondering if someone has come accross this or can help.
I have created a GUI Label in my code so that it displays the score as a label in my game, but for some reason it does not show up in my game. Can some one tell me what i am doing wrong or what i should be doing as i have created the function for GUI label but its not working. I have put this in my shooter class this script is attached to my main camera which acts as th player ![]()
using UnityEngine;
using System.Collections;
public class shooter : MonoBehaviour
{
public Rigidbody projectile; // prefab on it
public Transform shotPos; // empty gameobject where to shoot from
public float shotForce = 1000f; //force of the projectile
public float moveSpeed = 10f; // speed of camera
public float forwardSpeed = 0.0f; // forward speed
public float backwardSpeed = 0.0f; // backward speed
public static int Score = 0;
public static int Lives = 3;
// Update is called once per frame
void Update ()
{
// x axis
float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
transform.Translate(new Vector3(h,0,0));
if(Input.GetKey(KeyCode.F))
{
transform.Translate(new Vector3(0,0,forwardSpeed)* Time.deltaTime);
}
if(Input.GetKey(KeyCode.B))
{
transform.Translate(new Vector3(0,0,-backwardSpeed)* Time.deltaTime);
}
if(Input.GetButtonUp("Fire1"))
{
Rigidbody shot = Instantiate(projectile, shotPos.position, shotPos.rotation)as Rigidbody;
shot.AddForce(shotPos.forward * shotForce);
}
// Display the score on the screen as a label
}
void OnGui() // called every frame
{
GUI.Label(new Rect(20,10,100,100), "Score: " + shooter.Score.ToString());
}
}