[RESOLVIDO] Porta com senha!
3 participantes
SchultzGames :: UNITY 3D :: Resolvidos
Página 1 de 1
[RESOLVIDO] Porta com senha!
Galera eu preciso de um script de uma porta com senha.
tipo eu chego na porta e aperto "e" ai aparece pra por a senha clicando em cada numero na imagem,ai a porta abre, e se der erro ai sai um som.
tipo eu chego na porta e aperto "e" ai aparece pra por a senha clicando em cada numero na imagem,ai a porta abre, e se der erro ai sai um som.
LeonradoGp- Membro
- PONTOS : 3424
REPUTAÇÃO : 3
Idade : 24
Respeito as regras :
Re: [RESOLVIDO] Porta com senha!
Cara, isto é um pouco complexo de fazer... Não o sistema de comparação de senha em si, más a parte do digitador.
Dá uma olhada neste script básico que eu fiz para ir na camera:
Dá uma olhada neste script básico que eu fiz para ir na camera:
- Código:
using UnityEngine;
using System.Collections;
public class Senha : MonoBehaviour {
public string senha;
private string senhaTXT;
private GUIStyle style;
void Start(){
senhaTXT = string.Empty;
style = new GUIStyle();
}
void OnGUI(){
//numeros da senha
GUI.Box(new Rect(Screen.width / 2.61f, Screen.height / 8, Screen.width / 4.3f, Screen.height / 8), senhaTXT);
// 1 - 2 - 3
if (GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 3, Screen.width / 14, Screen.height / 8), "1")) {
senhaTXT = senhaTXT + "1";
}
if (GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 3, Screen.width / 14, Screen.height / 8), "2")) {
senhaTXT = senhaTXT + "2";
}
if (GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 3, Screen.width / 14, Screen.height / 8), "3")) {
senhaTXT = senhaTXT + "3";
}
// 4 - 5 - 6
if (GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 2.1f, Screen.width / 14, Screen.height / 8), "4")) {
senhaTXT = senhaTXT + "4";
}
if (GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 2.1f, Screen.width / 14, Screen.height / 8), "5")) {
senhaTXT = senhaTXT + "5";
}
if (GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 2.1f, Screen.width / 14, Screen.height / 8), "6")) {
senhaTXT = senhaTXT + "6";
}
// 7 - 8 - 9
if (GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 1.6f, Screen.width / 14, Screen.height / 8), "7")) {
senhaTXT = senhaTXT + "7";
}
if (GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 1.6f, Screen.width / 14, Screen.height / 8), "8")) {
senhaTXT = senhaTXT + "8";
}
if (GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 1.6f, Screen.width / 14, Screen.height / 8), "9")) {
senhaTXT = senhaTXT + "9";
}
// * - 0 - #
if (GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 1.3f, Screen.width / 14, Screen.height / 8), "*")) {
senhaTXT = senhaTXT + "*";
}
if (GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 1.3f, Screen.width / 14, Screen.height / 8), "0")) {
senhaTXT = senhaTXT + "0";
}
if (GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 1.3f, Screen.width / 14, Screen.height / 8), "#")) {
senhaTXT = senhaTXT + "#";
}
// RESSETAR OU CONFIRMAR
if (GUI.Button (new Rect (Screen.width / 1.5f, Screen.height / 1.7f, Screen.width / 5, Screen.height / 8), "RESSETAR")) {
senhaTXT = string.Empty;
}
if (GUI.Button (new Rect (Screen.width / 1.5f, Screen.height / 2.5f, Screen.width / 5, Screen.height / 8), "CONFIRMAR")) {
if(senhaTXT == senha){
senhaTXT = "Senha Correta";
}else{
senhaTXT = "Senha Incorreta";
}
}
}
}
Re: [RESOLVIDO] Porta com senha!
e como eu faço para esse script ser executado só quando eu apertar a letra "E" na porta?? e tbm quando ele digitar a senha correta carregar outra scene?
LeonradoGp- Membro
- PONTOS : 3424
REPUTAÇÃO : 3
Idade : 24
Respeito as regras :
Re: [RESOLVIDO] Porta com senha!
Use a função "OnTriggerEnter" para detectar se esta perto da porta ou um "Vector3.Distance"
Depois faça um simples if para quando você apertar "e", alguma bariavel booleana fica verdadeira. Depois basta colocar os comandos GUI de senha dentro de uma condição em que a variavel booleana necessita estar verdadeira.
Depois faça um simples if para quando você apertar "e", alguma bariavel booleana fica verdadeira. Depois basta colocar os comandos GUI de senha dentro de uma condição em que a variavel booleana necessita estar verdadeira.
teste
Opa boa tarde , eu nao entendo nada de programação , e eu estava querendo mesma coisa que voce, ai vi o que o Marcos postou, e juntei com script da porta que ele mesmo colocou, ai consegui, agora caso esteja errado mau ae pessoal ^^
ESSE SCRIPT E SEM 'TELEPORTE'
assim quando vc chegar perto dela e apertar "E" ela ira abrir o painel com senha.
criar um Script com nome : Codigocamera e joga no objeto vazio de sua porta
esse script voce so cria se quiser que ela abra e feche normalmente.
Criar outro script com nome PortaAoContrario e joga no objeto vazio de sua porta e desabilita ele no unity
esse e o mesmo script que marcos postou no forum aqui "Chaves"
so que mudei para negativo.
Creditos : MarcosSchultz :D . vlw flw
ESSE SCRIPT E SEM 'TELEPORTE'
assim quando vc chegar perto dela e apertar "E" ela ira abrir o painel com senha.
criar um Script com nome : Codigocamera e joga no objeto vazio de sua porta
- Código:
using UnityEngine;
using System.Collections;
public class Codigocamera : MonoBehaviour {
public string senha;
private string senhaTXT;
private GUIStyle style;
private GameObject Jogador;
private bool PodeAbrir;
public float distanciaParaAbrir = 2;
public bool AtivarGui = false;
private float RotacaoFechada,RotacaoAberta;
private bool MovimentarPorta,EstaAberta;
public float VelocidadeDeGiro = 60;
private float CronometroDoAviso,CronometroMovimento;
private Codigocamera script; // "Codigocamera" nome desse script - troque para nome de seu script
private PortaAoContrario script1; // "PortaAoContario" nome do script da porta normal
void Start(){
script = GetComponent<Codigocamera>(); //"Codigocamera" nome desse script
script1 = GetComponent<PortaAoContrario>(); // "PortaAoContario" nome do script da porta normal
EstaAberta = false;
senhaTXT = string.Empty;
style = new GUIStyle();
Jogador = GameObject.FindWithTag ("Player");
RotacaoFechada = transform.eulerAngles.y;
RotacaoAberta = transform.eulerAngles.y + 90;
if (RotacaoAberta > 360) {
RotacaoAberta = transform.eulerAngles.y + 90 -360;
}
}
void Update (){
// CHECAHDO SE ESTA PERTO OU NAO
if (Input.GetKeyDown ("e") && Vector3.Distance (transform.position, Jogador.transform.position) <= distanciaParaAbrir && AtivarGui == false) {
PodeAbrir = true;
AtivarGui = true;
} else if (Vector3.Distance (transform.position, Jogador.transform.position) > distanciaParaAbrir) {
PodeAbrir = false;
AtivarGui = false;
}
{
if (Input.GetKeyDown ("escape") && AtivarGui == true)
AtivarGui = false;
}
if (MovimentarPorta == true) {
CronometroMovimento += Time.deltaTime;
}
if (CronometroMovimento >= 2 + 75 / VelocidadeDeGiro) {
MovimentarPorta = false;
CronometroMovimento = 0;
EstaAberta = !EstaAberta;
script.enabled = false; // depois que o movimento da porta for concluido, desabilitar esse script
script1.enabled = true; // depois que o movimento da porta for concluido, ativar script da porta
}
}
void FixedUpdate (){
if (MovimentarPorta == true && EstaAberta == false) {
Vector3 rotacaoFinal = new Vector3(0,RotacaoAberta,0);
transform.eulerAngles = Vector3.Lerp (transform.eulerAngles,rotacaoFinal,Time.deltaTime*(VelocidadeDeGiro/50));
}
// MOVIMENTO DE FECHAR A PORTA
else if (MovimentarPorta == true && EstaAberta == true) {
Vector3 rotacaoFinal = new Vector3(0,RotacaoFechada,0);
transform.eulerAngles = Vector3.Lerp (transform.eulerAngles,rotacaoFinal,Time.deltaTime*(VelocidadeDeGiro/50));
}
}
void OnGUI(){
//numeros da senha
if(AtivarGui == true)
GUI.Box(new Rect(Screen.width / 2.61f, Screen.height / 8, Screen.width / 4.3f, Screen.height / 8), senhaTXT);
// 1 - 2 - 3
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 3, Screen.width / 14, Screen.height / 8), "1")) {
senhaTXT = senhaTXT + "1";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 3, Screen.width / 14, Screen.height / 8), "2")) {
senhaTXT = senhaTXT + "2";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 3, Screen.width / 14, Screen.height / 8), "3")) {
senhaTXT = senhaTXT + "3";
}
// 4 - 5 - 6
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 2.1f, Screen.width / 14, Screen.height / 8), "4")) {
senhaTXT = senhaTXT + "4";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 2.1f, Screen.width / 14, Screen.height / 8), "5")) {
senhaTXT = senhaTXT + "5";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 2.1f, Screen.width / 14, Screen.height / 8), "6")) {
senhaTXT = senhaTXT + "6";
}
// 7 - 8 - 9
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 1.6f, Screen.width / 14, Screen.height / 8), "7")) {
senhaTXT = senhaTXT + "7";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 1.6f, Screen.width / 14, Screen.height / 8), "8")) {
senhaTXT = senhaTXT + "8";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 1.6f, Screen.width / 14, Screen.height / 8), "9")) {
senhaTXT = senhaTXT + "9";
}
// * - 0 - #
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.61f, Screen.height / 1.3f, Screen.width / 14, Screen.height / 8), "*")) {
senhaTXT = senhaTXT + "*";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 2.16f, Screen.height / 1.3f, Screen.width / 14, Screen.height / 8), "0")) {
senhaTXT = senhaTXT + "0";
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 1.835f, Screen.height / 1.3f, Screen.width / 14, Screen.height / 8), "#")) {
senhaTXT = senhaTXT + "#";
}
// RESSETAR OU CONFIRMAR
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 1.5f, Screen.height / 1.7f, Screen.width / 5, Screen.height / 8), "RESETAR")) {
senhaTXT = string.Empty;
}
if (AtivarGui == true && GUI.Button (new Rect (Screen.width / 1.5f, Screen.height / 2.5f, Screen.width / 5, Screen.height / 8), "CONFIRMAR")) {
if(senhaTXT == senha){
senhaTXT = "Senha Correta";
MovimentarPorta = true;
EstaAberta = false;
}else{
senhaTXT = "Senha Incorreta";
}
}
}
}
esse script voce so cria se quiser que ela abra e feche normalmente.
Criar outro script com nome PortaAoContrario e joga no objeto vazio de sua porta e desabilita ele no unity
esse e o mesmo script que marcos postou no forum aqui "Chaves"
so que mudei para negativo.
- Código:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(AudioSource))]
public class PortaAoContrario : MonoBehaviour {
public bool EstaTrancada,PrecisaDeChave;
public AudioClip PortaNormal,PortaTrancada,SomDeChave;
public float distanciaParaAbrir = 3;
public Font Fonte;
public float VelocidadeDeGiro = 60;
public int IDdaPorta;
public static List<int> ListaDeIDs = new List<int>(); // LISTA DE CHAVES QUE O PLAYER CONTEM
private bool MovimentarPorta, EstaAberta,PodeAbrir,AvisoTrancada,temAChave;
private float CronometroDoAviso,CronometroMovimento;
private float RotacaoFechada,RotacaoAberta;
private GameObject Jogador;
void Start (){
EstaAberta = false;
AvisoTrancada = false;
temAChave = false;
RotacaoFechada = transform.eulerAngles.y;
RotacaoAberta = transform.eulerAngles.y - 90;
if (RotacaoAberta > 360) {
RotacaoAberta = transform.eulerAngles.y + 90 -360;
}
Jogador = GameObject.FindWithTag ("Player");
if (PrecisaDeChave == true) {
EstaTrancada = true;
}
}
void Update (){
// CHECAHDO SE ESTA PERTO OU NAO
if (Vector3.Distance (transform.position, Jogador.transform.position) <= distanciaParaAbrir) {
PodeAbrir = true;
} else if (Vector3.Distance (transform.position, Jogador.transform.position) > distanciaParaAbrir) {
PodeAbrir = false;
}
//CHECANDO SE ESTA TRANCADA OU NAO... SE NAO ESTIVER, PODE ABRIR
if (EstaTrancada == false) {
if(Input.GetKeyDown("e") && MovimentarPorta == true && PodeAbrir == true){
CronometroMovimento = 0;
EstaAberta = !EstaAberta;
GetComponent<AudioSource>().Stop ();
GetComponent<AudioSource>().PlayOneShot(PortaNormal);
}
else if(Input.GetKeyDown("e") && PodeAbrir == true && MovimentarPorta == false){
GetComponent<AudioSource>().PlayOneShot(PortaNormal);
MovimentarPorta = true;
}
}
// SE A PORTA ESTIVER TRANCADA
if (Input.GetKeyDown ("e") && PodeAbrir == true && EstaTrancada == true) {
//CHECA SE O PALYER TEM A CHAVE OU NAO
for(int x = 0; x < ListaDeIDs.Count; x++){
if(IDdaPorta == ListaDeIDs[x]){
temAChave = true;
}else{
temAChave = false;
}
}
// SE O PALYER TEM A CHAVE
if(temAChave == true && PrecisaDeChave == true){
EstaTrancada = false;
if(!GetComponent<AudioSource>().isPlaying){
GetComponent<AudioSource>().PlayOneShot(SomDeChave);
}
}
// SE O PALYER NAO TEM A CHAVE
else {
AvisoTrancada = true;
if(!GetComponent<AudioSource>().isPlaying){
GetComponent<AudioSource>().PlayOneShot(PortaTrancada);
}
}
}
// CRONOMETRO DO AVISO DA PORTA TRANCADA
if (AvisoTrancada == true) {
CronometroDoAviso += Time.deltaTime;
}
if (CronometroDoAviso >= 3) {
AvisoTrancada = false;
CronometroDoAviso = 0;
}
// CRONOMETRO DO MOVIMENTO DA PORTA
if (MovimentarPorta == true) {
CronometroMovimento += Time.deltaTime;
}
if(CronometroMovimento >= 2 + 75/VelocidadeDeGiro){
MovimentarPorta = false;
CronometroMovimento = 0;
EstaAberta = !EstaAberta;
}
}
void FixedUpdate (){
// MOVIMENTO DE ABRIR A PORTA
if (MovimentarPorta == true && EstaAberta == false) {
Vector3 rotacaoFinal = new Vector3(0,RotacaoAberta,0);
transform.eulerAngles = Vector3.Lerp (transform.eulerAngles,rotacaoFinal,Time.deltaTime*(VelocidadeDeGiro/50));
}
// MOVIMENTO DE FECHAR A PORTA
else if (MovimentarPorta == true && EstaAberta == true) {
Vector3 rotacaoFinal = new Vector3(0,RotacaoFechada,0);
transform.eulerAngles = Vector3.Lerp (transform.eulerAngles,rotacaoFinal,Time.deltaTime*(VelocidadeDeGiro/50));
}
}
void OnGUI (){
// AVISO SOBRE PORTA TRANCADA
GUI.skin.font = Fonte;
GUI.skin.label.fontSize = Screen.height / 20;
if (AvisoTrancada == true) {
if(PrecisaDeChave == true){
GUI.Label(new Rect(Screen.width/2-Screen.width/5,Screen.height/2-Screen.height/16,Screen.width/2.5f,Screen.height/8),"Voce precisa de uma chave");
}
else if(PrecisaDeChave == false){
GUI.Label(new Rect(Screen.width/2-Screen.width/5,Screen.height/2-Screen.height/16,Screen.width/2.5f,Screen.height/8),"Nunca ira abrir");
}
}
}
}
Creditos : MarcosSchultz :D . vlw flw
bianchi31- Iniciante
- PONTOS : 3280
REPUTAÇÃO : 2
Respeito as regras :
Re: [RESOLVIDO] Porta com senha!
Obrigado!!! Funciono direitinho vlw man!!!
LeonradoGp- Membro
- PONTOS : 3424
REPUTAÇÃO : 3
Idade : 24
Respeito as regras :
Tópicos semelhantes
» [RESOLVIDO] script senha para bool
» [RESOLVIDO] Erro na bool para senha
» [RESOLVIDO] Porta de elevador
» [RESOLVIDO] Gerador de senha
» [RESOLVIDO] Senha jogo schultz
» [RESOLVIDO] Erro na bool para senha
» [RESOLVIDO] Porta de elevador
» [RESOLVIDO] Gerador de senha
» [RESOLVIDO] Senha jogo schultz
SchultzGames :: UNITY 3D :: Resolvidos
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos