[TUTORIAL] Sistema de "Entrar" em locais
Página 1 de 1
[TUTORIAL] Sistema de "Entrar" em locais
Olá a todos! Tudo blz?
Desenvolvi esse simples sistema para um game que estou fazendo
Ele é um sistema de complemento/utilitário já que necessita de outro script para fazer efeito
Basicamente ele verifica se o jogador está no trigger e chama determinada void um script especificado quando o player aperta um determinado botão, ou quando ele encosta no trigger
Desenvolvi esse simples sistema para um game que estou fazendo
Ele é um sistema de complemento/utilitário já que necessita de outro script para fazer efeito
Basicamente ele verifica se o jogador está no trigger e chama determinada void um script especificado quando o player aperta um determinado botão, ou quando ele encosta no trigger
- Código:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine;
public class Enter : MonoBehaviour {
public MonoBehaviour Script;
public string CallVoid;
[System.Serializable]
public enum _CallType
{
Automatic, ByKey
}
[SerializeField]
public _CallType CallType = _CallType.ByKey;
public string ButtonName = "Interact2";
[Space]
public bool CheckIfIsLocalPlayer;
bool PlayerOnTrigger;
public MonoBehaviour PlayerHere;
void Update()
{
if (!PlayerHere)
return;
if (CallType == _CallType.ByKey)
{
if (Input.GetButtonUp(ButtonName))
{
PlayerHere.Invoke(CallVoid, 0);
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.GetComponent(Script.GetType()))
{
if (!CheckIfIsLocalPlayer)
{
PlayerOnTrigger = true;
PlayerHere = other.GetComponent(Script.GetType()) as MonoBehaviour;
} else
{
if (other.GetComponent<NetworkIdentity>().isLocalPlayer)
{
PlayerOnTrigger = true;
PlayerHere = other.GetComponent(Script.GetType()) as MonoBehaviour;
}
}
if(CallType == _CallType.Automatic)
{
PlayerHere.Invoke(CallVoid, 0);
}
}
}
void OnTriggerExit(Collider other)
{
if (other.GetComponent(Script.GetType()))
{
if (!CheckIfIsLocalPlayer)
{
PlayerOnTrigger = false;
PlayerHere = null;
}
else
{
if (other.GetComponent<NetworkIdentity>().isLocalPlayer)
{
PlayerOnTrigger = false;
PlayerHere = null;
}
}
}
}
}
Última edição por dstaroski em Sex 8 Mar 2019 - 10:27, editado 1 vez(es) (Motivo da edição : Adicionado Tutorial no início do título)

» Erro Sistema de entrar no veiculo
» [TUTORIAL] Sistema de DIA E NOITE completo, com luzes noturnas e SISTEMA DE NUVENS
» [TUTORIAL] Entrar no carro estilo GTA
» [TUTORIAL] Sistema de Interruptor
» [TUTORIAL] Sistema de Velocimetro
» [TUTORIAL] Sistema de DIA E NOITE completo, com luzes noturnas e SISTEMA DE NUVENS
» [TUTORIAL] Entrar no carro estilo GTA
» [TUTORIAL] Sistema de Interruptor
» [TUTORIAL] Sistema de Velocimetro
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos