Advertisement
VizKa

Change Sensitivity On Input

May 5th, 2023
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.06 KB | Gaming | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Cinemachine;
  5. using UnityEngine;
  6. using UnityEngine.InputSystem;
  7.  
  8. public class ChangeSensOnInput : PlayerCameras
  9. {
  10.     //Mouse and Keyboard
  11.    
  12.     //FreeLook M&K values Spark
  13.     private float xSensibilityFreeLookMandKSpark = 120f;
  14.     private float ySensibilityFreeLookMandKSpark = 0.7f;
  15.    
  16.     //Aim M&K values Spark
  17.     private float xSensibilityAimMandKSpark = 120f;
  18.     private float ySensibilityAimMandKSpark = 0.7f;
  19.    
  20.     //FreeLook M&K values Kling
  21.     private float xSensibilityFreeLookMandKKling = 150f;
  22.     private float ySensibilityFreeLookMandKKling = 0.9f;
  23.    
  24.     //Aim M&K values Kling
  25.     private float xSensibilityAimMandKKling = 80f;
  26.     private float ySensibilityAimMandKKling = 0.3f;
  27.  
  28.     //Gamepad
  29.  
  30.     //FreeLook pad values Spark
  31.     private float xSensibilityFreeLookGamepadSpark = 220f;
  32.     private float ySensibilityFreeLookGamepadSpark = 1f;
  33.    
  34.     //Aim pad values Spark
  35.     private float xSensibilityAimGamepadSpark = 60f;
  36.     private float ySensibilityAimGamepadSpark = 0.25f;
  37.  
  38.     //FreeLook pad values Kling
  39.     private float xSensibilityFreeLookGamepadKling = 200f;
  40.     private float ySensibilityFreeLookGamepadKling = 1f;
  41.    
  42.     //Aim pad values Kling
  43.     private float xSensibilityAimGamepadKling = 70f;
  44.     private float ySensibilityAimGamepadKling = 0.5f;
  45.  
  46.     private PlayerInput klingInput;
  47.     private PlayerInput sparkInput;
  48.    
  49.     private protected override void Awake()
  50.     {
  51.         //Get player input of Spark
  52.         sparkInput = getPlayerInput(Spark);
  53.        
  54.         //Get player input of Kling
  55.         klingInput = getPlayerInput(Kling);
  56.     }
  57.  
  58.     private PlayerInput getPlayerInput(GameObject character)
  59.     {
  60.         Transform InputTransform = character.transform.Find("Smooth Player Controller");
  61.         return InputTransform.GetComponent<PlayerInput>();
  62.     }
  63.  
  64.     public void ChangeSensitivityBasedOnControlScheme()
  65.     {
  66.         SetCameraSensitivityKling(klingInput.currentControlScheme == "Gamepad");
  67.         SetCameraSensitivitySpark(sparkInput.currentControlScheme == "Gamepad");
  68.     }
  69.  
  70.  
  71.     private void SetCameraSensitivitySpark(bool gamepad)
  72.     {
  73.         if (gamepad)
  74.         {
  75.             //Set Spark Gamepad FreeLook values
  76.             FreeLookSpark.m_XAxis.m_MaxSpeed = xSensibilityFreeLookGamepadSpark;
  77.             FreeLookSpark.m_YAxis.m_MaxSpeed = ySensibilityFreeLookGamepadSpark;
  78.            
  79.             //Set Spark Gamepad Aim values
  80.             AimSpark.m_XAxis.m_MaxSpeed = xSensibilityAimGamepadSpark;
  81.             AimSpark.m_YAxis.m_MaxSpeed = ySensibilityAimGamepadSpark;
  82.         }
  83.         else
  84.         {
  85.             //Set Spark M&K FreeLook values
  86.             FreeLookSpark.m_XAxis.m_MaxSpeed = xSensibilityFreeLookMandKSpark;
  87.             FreeLookSpark.m_YAxis.m_MaxSpeed = ySensibilityFreeLookMandKSpark;
  88.            
  89.             //Set Spark M&K Aim values
  90.             AimSpark.m_XAxis.m_MaxSpeed = xSensibilityAimMandKSpark;
  91.             AimSpark.m_YAxis.m_MaxSpeed = ySensibilityAimMandKSpark;
  92.         }
  93.     }
  94.    
  95.     private void SetCameraSensitivityKling(bool gamepad)
  96.     {
  97.         if (gamepad)
  98.         {
  99.             //Set Kling Gamepad FreeLook values
  100.             FreeLookKling.m_XAxis.m_MaxSpeed = xSensibilityFreeLookGamepadKling;
  101.             FreeLookKling.m_YAxis.m_MaxSpeed = ySensibilityFreeLookGamepadKling;
  102.            
  103.             //Set Kling Gamepad Aim values
  104.             AimKling.m_XAxis.m_MaxSpeed = xSensibilityAimGamepadKling;
  105.             AimKling.m_YAxis.m_MaxSpeed = ySensibilityAimGamepadKling;
  106.         }
  107.         else
  108.         {
  109.             //Set Kling M&K FreeLook values
  110.             FreeLookKling.m_XAxis.m_MaxSpeed = xSensibilityFreeLookMandKKling;
  111.             FreeLookKling.m_YAxis.m_MaxSpeed = ySensibilityFreeLookMandKKling;
  112.            
  113.             //Set Kling M&K Aim values
  114.             AimKling.m_XAxis.m_MaxSpeed = xSensibilityAimMandKKling;
  115.             AimKling.m_YAxis.m_MaxSpeed = ySensibilityAimMandKKling;
  116.         }
  117.     }
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement