Last active
August 29, 2015 14:07
-
-
Save enricllagostera/a280be4ec29ee5858fcc to your computer and use it in GitHub Desktop.
Temos um array com 5 elementos, com o nome de 5 itens que a personagem carrega na mochila. Quando a personagem chega numa porta, queremos detectar automaticamente se tem ou não uma chave para abri-la. Crie um script TemChave que percorre a array comparando se cada item tem o nome “chave” e escreve verdadeiro se encontrar alguma. Caso contrário, …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class TemChave : MonoBehaviour | |
{ | |
// definido no Inspector | |
public string[] inventario; | |
void Start () | |
{ | |
bool encontrou = false; | |
for (int ind = 0; ind < 5; ind++) { | |
if (inventario[ind] == "chave") { | |
encontrou = true; | |
} | |
} | |
print(encontrou); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment