Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //El script se debe añadir dentro del collider al que van entrar para que les funcione
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityStandardAssets.Characters.FirstPerson;
- public class Escondite : MonoBehaviour {
- public GameObject Player;
- private bool JugadorEscondido;
- public Transform padre;
- public Transform fueraEscondite;
- private FirstPersonController fps;
- void Start () {
- JugadorEscondido = false;
- }
- void Update () {
- Player = GameObject.FindGameObjectWithTag ("Player");
- fps = Player.GetComponent<FirstPersonController> ();
- if (Input.GetKeyDown(KeyCode.Mouse0) && JugadorEscondido) {
- Player.transform.SetParent (null);
- Player.transform.localPosition = new Vector3 (fueraEscondite.position.x, fueraEscondite.position.y, fueraEscondite.position.z);
- Player.transform.localRotation = Quaternion.Euler (fueraEscondite.rotation.x, fueraEscondite.rotation.y, fueraEscondite.rotation.z);
- JugadorEscondido = !JugadorEscondido;
- fps.m_WalkSpeed = 5;
- fps.m_RunSpeed = 10;
- }
- }
- void OnTriggerStay (Collider col) {
- if (col.tag == "Player") {
- if (!JugadorEscondido && Input.GetKeyUp (KeyCode.Mouse0)) {
- Player.transform.localPosition = new Vector3 (padre.position.x, padre.position.y, padre.position.z);
- Player.transform.localRotation = Quaternion.Euler (padre.rotation.x, padre.rotation.y, padre.rotation.z);
- Player.transform.SetParent (padre);
- JugadorEscondido = !JugadorEscondido;
- fps.m_WalkSpeed = 0;
- fps.m_RunSpeed = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement