Somar int, como faz pra ele adicionar o valor que eu quero.
2 participantes
Página 1 de 1
Somar int, como faz pra ele adicionar o valor que eu quero.
- Código:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Municao : MonoBehaviour {
[Header("Teclas")]
public KeyCode TeclaPegarMunicao = KeyCode.E;
[Space(10)]
[Header("Conectar objetos")]
public GameObject Obj;
private bool podePegarOItem = false;
[Space(10)]
[Header("Configuraçoes")]
public int MunicaoPegar = 10;
Arma scriptInstance = null;
public int balaspentearma;
public int balasarma;
public AudioSource audioSource;
public AudioClip clip;
public float Tempo=1.0f;
void Start(){
GameObject tempObj = GameObject.Find("Glock");
scriptInstance = tempObj.GetComponent<Arma>();
}
void Update () {
scriptInstance.balasPente = balaspentearma;
scriptInstance.balas = balasarma;
if (Input.GetKeyDown (TeclaPegarMunicao) && podePegarOItem == true) {
audioSource.PlayOneShot(clip);
StartCoroutine ("Peguei");
balasarma + MunicaoPegar;
}
}
void OnGUI(){
if (podePegarOItem == true) {
GUIStyle stylez = new GUIStyle ();
stylez.alignment = TextAnchor.MiddleCenter;
GUI.skin.label.fontSize = 20;
GUI.Label (new Rect (Screen.width / 2 - 50, Screen.height / 2 + 50, 200, 30), "Pressione: " + TeclaPegarMunicao);
}
}
void OnTriggerEnter(Collider other)
{
podePegarOItem = true;
}
void OnTriggerExit(Collider other) {
podePegarOItem = false;
}
}
Felipe42- Avançado
- PONTOS : 1675
REPUTAÇÃO : 1
Respeito as regras :
Re: Somar int, como faz pra ele adicionar o valor que eu quero.
lembrando que estou na versao da unity 2017.2020. eu tento somar 2 int mas da erro.
Felipe42- Avançado
- PONTOS : 1675
REPUTAÇÃO : 1
Respeito as regras :
Re: Somar int, como faz pra ele adicionar o valor que eu quero.
Quando quiser somar um valor ao valor atual, utilize (+=)
- Código:
balasarma += MunicaoPegar;
- Código:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Municao : MonoBehaviour
{
[Header("Teclas")]
public KeyCode TeclaPegarMunicao = KeyCode.E;
[Space(10)]
[Header("Conectar objetos")]
public GameObject Obj;
private bool podePegarOItem = false;
[Space(10)]
[Header("Configuraçoes")]
public int MunicaoPegar = 10;
Arma scriptInstance = null;
public int balaspentearma;
public int balasarma;
public AudioSource audioSource;
public AudioClip clip;
public float Tempo = 1.0f;
void Start()
{
GameObject tempObj = GameObject.Find("Glock");
scriptInstance = tempObj.GetComponent<Arma>();
}
void Update()
{
scriptInstance.balasPente = balaspentearma;
scriptInstance.balas = balasarma;
if (Input.GetKeyDown(TeclaPegarMunicao) && podePegarOItem == true)
{
audioSource.PlayOneShot(clip);
StartCoroutine("Peguei");
balasarma += MunicaoPegar;
}
}
void OnGUI()
{
if (podePegarOItem == true)
{
GUIStyle stylez = new GUIStyle();
stylez.alignment = TextAnchor.MiddleCenter;
GUI.skin.label.fontSize = 20;
GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 50, 200, 30), "Pressione: " + TeclaPegarMunicao);
}
}
void OnTriggerEnter(Collider other)
{
podePegarOItem = true;
}
void OnTriggerExit(Collider other)
{
podePegarOItem = false;
}
}
Fagner- Moderador
-
PONTOS : 4087
REPUTAÇÃO : 665
Áreas de atuação : Modelagem 3D, Programação.
Respeito as regras :

» Como adicionar sistema de cash?
» quero adicionar mais colisores a esse script de movimentação
» Pegar Valor int, Como?
» quero instanciar um obj vazio como faço?
» Como adicionar animações FPS em um char TPP
» quero adicionar mais colisores a esse script de movimentação
» Pegar Valor int, Como?
» quero instanciar um obj vazio como faço?
» Como adicionar animações FPS em um char TPP
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos