Advertisement
Diamond32_Tutoriales

PerZoneCamera

May 16th, 2021
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(BoxCollider))]
  6. [ExecuteInEditMode]
  7. public class PerZoneCamera : MonoBehaviour
  8. {
  9.     public string ZoneName;
  10.     [Space(10)]
  11.     public FirstPersonAIO fpsScript;
  12.     public ThirdPerson tdsScript;
  13.     public GameObject FPS, TDS;
  14.     public BoxCollider colision;
  15.     [Space(10)]
  16.     public Color Zonecolor;
  17.     [Space(10)]
  18.     public Vector3 ZoneSize;
  19.     public string TagName;
  20.     public bool isEnter;
  21.      public Transform originalCamera;
  22.     public Transform LookOBJ;
  23.     public CharacterController CCTDS;
  24.  
  25.     private void Start()
  26.     {
  27.         colision = GetComponent <BoxCollider>();
  28.     }
  29.  
  30.  
  31.     private void Update()
  32.     {
  33.         this.transform.name = ZoneName;
  34.         colision.size = ZoneSize;
  35.  
  36.         colision.isTrigger = true;
  37.     }
  38.  
  39.     private void OnDrawGizmos()
  40.     {
  41.         Gizmos.color = Zonecolor;
  42.         Gizmos.DrawCube(transform.position, ZoneSize);
  43.     }
  44.  
  45.     private void OnTriggerEnter(Collider other)
  46.     {
  47.         if (other.tag == TagName)
  48.         {
  49.             isEnter = true;
  50.             Invoke("ActivarTerceraPersona", 0.3f);
  51.         }
  52.     }
  53.  
  54.  
  55.     private void OnTriggerExit(Collider other)
  56.     {
  57.         if (other.tag == TagName)
  58.         {
  59.             isEnter = false;
  60.             tdsScript.camera = originalCamera;
  61.  
  62.             Invoke("UsarPrimeraPersona", 1f);
  63.         }
  64.     }
  65.  
  66.     void ActivarTerceraPersona()
  67.     {
  68.         FPS.SetActive(false);
  69.         TDS.SetActive(true);
  70.         TDS.transform.position = FPS.transform.position;
  71.         fpsScript.enabled = false;
  72.         tdsScript.enabled = true;
  73.         CCTDS.enabled = true;
  74.     }
  75.  
  76.     void UsarPrimeraPersona()
  77.     {
  78.         FPS.SetActive(true);
  79.         TDS.SetActive(false);
  80.         FPS.transform.position = TDS.transform.position;
  81.         tdsScript.enabled = false;
  82.         fpsScript.enabled = true;
  83.         CCTDS.enabled = false;
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement