Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: Unity3D 5 - C# - přidání textu do scriptu

Aktivity
Avatar
Nakaii
Člen
Avatar
Nakaii:1.3.2016 17:50

Ahoj, potřeboval bych poradit ohledně přidání textu do tohoto scriptu.
Script ukazuje stav životů, jídla a výdrže, a potřeboval bych, aby v každém okénku byl určitý text.
Script:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;


public class PlayerGUI : MonoBehaviour
{

    //Size of Textures
    Vector2 size = new Vector2(180, 30);

    //Health Variables
    [SerializeField]
    private Vector2 healthPos = new Vector2(140, 20);
    [SerializeField]
    private float healthBarDisplay = 1f;
    [SerializeField]
    private Texture2D healthBarEmpty;
    [SerializeField]
    private Texture2D healthBarFull;


    //Hunger Variables
    [SerializeField]
    private Vector2 hungerPos = new Vector2(20, 60);
    [SerializeField]
    private float hungerBarDisplay = 1f;
    [SerializeField]
    private Texture2D hungerBarEmpty;
    [SerializeField]
    private Texture2D hungerBarFull;



    //Stamina Variables
    [SerializeField]
    public Vector2 staminaPos = new Vector2(20, 140);
    [SerializeField]
    public float staminaBarDisplay = 1f;
    [SerializeField]
    public Texture2D staminaBarEmpty;
    [SerializeField]
    public Texture2D staminaBarFull;

    //Fall rate
    [SerializeField]
    private int healthFallRate = 150;
    [SerializeField]
    private int hungerFallRate = 150;
    [SerializeField]
    private int staminaFallRate = 35;

    [SerializeField]
    private bool canJump = false;
    [SerializeField]
    private float jumpTimer = 0.7f;

    private UnityStandardAssets.Characters.FirstPerson.FirstPersonController chMotor;
    private CharacterController controller;


    void Start()
    {
        chMotor = GetComponent<UnityStandardAssets.Characters.FirstPerson.FirstPersonController>();
        controller = GetComponent<CharacterController>();
    }

    void OnGUI()
    {
        //Health GUI
        GUI.BeginGroup(new Rect(healthPos.x, healthPos.y, size.x, size.y));
        GUI.Box(new Rect(0, 0, size.x, size.y), healthBarEmpty);

        GUI.BeginGroup(new Rect(0, 0, size.x * healthBarDisplay, size.y));
        GUI.Box(new Rect(0, 0, size.x, size.y), healthBarFull);

        GUI.EndGroup();
        GUI.EndGroup();

        //Hunger GUI
        GUI.BeginGroup(new Rect(hungerPos.x, hungerPos.y, size.x, size.y));
        GUI.Box(new Rect(0, 0, size.x, size.y), hungerBarEmpty);

        GUI.BeginGroup(new Rect(0, 0, size.x * hungerBarDisplay, size.y));
        GUI.Box(new Rect(0, 0, size.x, size.y), hungerBarFull);

        GUI.EndGroup();
        GUI.EndGroup();


        //Stamina GUI
        GUI.BeginGroup(new Rect(staminaPos.x, staminaPos.y, size.x, size.y));
        GUI.Box(new Rect(0, 0, size.x, size.y), staminaBarEmpty);

        GUI.BeginGroup(new Rect(0, 0, size.x * staminaBarDisplay, size.y));
        GUI.Box(new Rect(0, 0, size.x, size.y), staminaBarFull);

        GUI.EndGroup();
        GUI.EndGroup();

    }

    void Update()
    {
        //HEALTH CONTROL SECTION
        if ((hungerBarDisplay <= 0))
        {
            healthBarDisplay -= Time.deltaTime / healthFallRate * 1;
        }
        else {
            if ((hungerBarDisplay <= 0))
            {
                healthBarDisplay -= Time.deltaTime / healthFallRate;
            }
        }

        if (healthBarDisplay <= 0)
        {
            CharacterDeath();
        }

        //HUNGER CONTROL SECTION
        if (hungerBarDisplay >= 0)
        {
            hungerBarDisplay -= Time.deltaTime / hungerFallRate;
        }

        if (hungerBarDisplay <= 10)
        {
            hungerBarDisplay = 1;
        }

        if (hungerBarDisplay >= 1)
        {
            hungerBarDisplay = 1;
        }




        //STAMINA CONTROL SECITON
        if (controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
        {
            chMotor.setRunSpeed(10);
            staminaBarDisplay -= Time.deltaTime / staminaFallRate;
        }
        else {
            chMotor.setRunSpeed(6);
            staminaBarDisplay += Time.deltaTime / staminaFallRate;
        }

        //JUMPING SECTION
        if (Input.GetKeyDown(KeyCode.Space) && canJump == true && chMotor.getGrounded() && staminaBarDisplay >= 0.05)
        {
            staminaBarDisplay -= 0.05f;
            chMotor.Jump();
            Wait();
        }

        if (canJump == false)
        {
            jumpTimer -= Time.deltaTime;
            chMotor.setJumpEnabled(false);
        }

        if (jumpTimer <= 0)
        {
            canJump = true;
            chMotor.setJumpEnabled(true);
            jumpTimer = 0.7f;
        }


        if (staminaBarDisplay <= 0.2)
        {
            canJump = false;
        }

        if (staminaBarDisplay >= 1)
        {
            staminaBarDisplay = 1;
        }

        if (staminaBarDisplay <= 0)
        {
            staminaBarDisplay = 0;
            chMotor.setRunSpeed(6);
        }
    }

    void CharacterDeath()
    {
        Application.LoadLevel("SIMPLELEVEL");
    }

    IEnumerator Wait()
    {
        yield return new WaitForSeconds(0.1f);
        canJump = false;

    }
}

Předem děkuji za odpověď :)

 
Odpovědět
1.3.2016 17:50
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 1 zpráv z 1.