Advertisement
VizKa

Change Camera Runtime

May 5th, 2023
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Cinemachine;
  5. using UnityEngine;
  6.  
  7. public class ChangeCameraSettingsRuntime : PlayerCameras
  8. {
  9.  
  10.     [Header("Kling Rigs Attributes")]
  11.     [SerializeField] private CinemachineFreeLook.Orbit newTopKling;
  12.     [SerializeField] private CinemachineFreeLook.Orbit newMidKling;
  13.     [SerializeField] private CinemachineFreeLook.Orbit newBottomKling;
  14.  
  15.     [Header("Spark Rigs Attributes")]
  16.     [SerializeField] private CinemachineFreeLook.Orbit newTopSpark;
  17.     [SerializeField] private CinemachineFreeLook.Orbit newMidSpark;
  18.     [SerializeField] private CinemachineFreeLook.Orbit newBottomSpark;
  19.  
  20.  
  21.     [Header("")]
  22.     [SerializeField] private bool isResettingToDefault;
  23.  
  24.     private protected override void Awake()
  25.     {
  26.        
  27.     }
  28.  
  29.     private void OnTriggerEnter(Collider other)
  30.     {
  31.         bool isKling = other.gameObject.layer == LayerIDs.PlayerMetal;
  32.         bool isSpark = other.gameObject.layer == LayerIDs.PlayerBolt;
  33.        
  34.         if (!isKling && !isSpark)
  35.         {
  36.             return;
  37.         }
  38.  
  39.         if (isKling)
  40.         {
  41.            
  42.             if(isResettingToDefault)
  43.             {
  44.                 ResetOrbitsToDefault(true);
  45.                 return;
  46.             }
  47.  
  48.             secondCameraKling.m_Orbits[0] = newTopKling;
  49.             secondCameraKling.m_Orbits[1] = newMidKling;
  50.             secondCameraKling.m_Orbits[2] = newBottomKling;
  51.  
  52.             ChangeKlingOrbits();
  53.            
  54.         }
  55.  
  56.         if (isSpark)
  57.         {
  58.            
  59.             if(isResettingToDefault)
  60.             {
  61.                 ResetOrbitsToDefault(false);
  62.                 return;
  63.             }
  64.            
  65.             secondCameraSpark.m_Orbits[0] = newTopSpark;
  66.             secondCameraSpark.m_Orbits[1] = newMidSpark;
  67.             secondCameraSpark.m_Orbits[2] = newBottomSpark;
  68.            
  69.             ChangeSparkOrbits();
  70.         }
  71.        
  72.     }
  73.  
  74.     private void ChangeKlingOrbits()
  75.     {
  76.         secondCameraKling.m_Priority = 11;
  77.         FreeLookKling.m_Priority = 10;
  78.     }
  79.  
  80.     private void ChangeSparkOrbits()
  81.     {
  82.         secondCameraSpark.m_Priority = 11;
  83.         FreeLookSpark.m_Priority = 10;
  84.     }
  85.  
  86.     private void ResetOrbitsToDefault(bool isKling)
  87.     {
  88.         if (isKling)
  89.         {
  90.             secondCameraKling.m_Priority = 10;
  91.             FreeLookKling.m_Priority = 11;
  92.         }
  93.         else
  94.         {
  95.             secondCameraSpark.m_Priority = 10;
  96.             FreeLookSpark.m_Priority = 11;
  97.         }
  98.     }
  99.  
  100.  
  101. }
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement