RaposoTKD

Untitled

May 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3.  
  4. public class PlayerJoystickManager : MonoBehaviour {
  5.  
  6.     [SerializeField] int base_p1 = -1;
  7.     [SerializeField] int base_p2 = -1;
  8.     [HideInInspector] public bool ready;
  9.     PlayerInputInfo player1_info, player2_info;
  10.  
  11.     static public PlayerJoystickManager instance;
  12.  
  13.     void Awake () {
  14.         if (!instance) {
  15.             instance = this;
  16.             DontDestroyOnLoad(this);
  17.  
  18.             if (base_p1 > -1) set_player_info(1, base_p1);
  19.             if (base_p2 > -1) set_player_info(2, base_p2);
  20.         } else {
  21.             Destroy(gameObject);
  22.         }
  23.     }
  24.  
  25.     public void set_player_info(int player_id, int controller_id) {
  26.         if (player_id == 1) {
  27.             if(controller_id < 0) {
  28.                 player1_info = null;
  29.                 return;
  30.             }
  31.             player1_info = new PlayerInputInfo();
  32.             player1_info.set_inputs(player_id, controller_id);
  33.             ready = true;
  34.         } else {
  35.             if (controller_id < 0) {
  36.                 player2_info = null;
  37.                 return;
  38.             }
  39.             player2_info = new PlayerInputInfo();
  40.             player2_info.set_inputs(player_id, controller_id);
  41.         }
  42.     }
  43.  
  44.     public PlayerInputInfo get_player_info(int player_id) {
  45.         if (player_id == 1)
  46.             return player1_info;
  47.         else
  48.             return player2_info;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment