Kyle_Dev

Omnious Obstacles - PlayerController -> Traps

Nov 5th, 2019
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5.  
  6. public class TrapPlayerController : MonoBehaviour
  7. {
  8.     int m_selectedtrap;
  9.     int m_lasttrap;
  10.     int m_nexttrap;
  11.  
  12.     [SerializeField]
  13.     int m_trapplayerindex;
  14.  
  15.     [SerializeField]
  16.     KeyCode player_nexttrapkey;
  17.     [SerializeField]
  18.     KeyCode player_previoustrapkey;
  19.     [SerializeField]
  20.     KeyCode player_activatetrapkey;
  21.  
  22.     TrapPlayerController[] m_theghosts;
  23.  
  24.     TrapManager m_trapmanager;
  25.  
  26.     [SerializeField]
  27.     List<Transform> m_activationposition;
  28.  
  29.     void Awake()
  30.     {
  31.         m_selectedtrap = 0;
  32.     }
  33.  
  34.     void Start ()
  35.     {
  36.         m_theghosts = GameObject.FindObjectsOfType<TrapPlayerController>();
  37.         m_trapmanager = GameObject.FindObjectOfType<TrapManager>();
  38.  
  39.         Debug.Log(m_trapplayerindex);
  40.         m_theghosts[m_trapplayerindex].m_selectedtrap = m_trapplayerindex;
  41.         m_trapmanager.GetTrap(m_selectedtrap).UseThisTrap(true);
  42.     }
  43.    
  44.     void Update ()
  45.     {
  46.         if (Input.GetKeyDown(player_nexttrapkey))
  47.         {
  48.             int newtrapindex = m_trapmanager.GetNextTrap(m_selectedtrap);
  49.  
  50.             if(newtrapindex != m_selectedtrap)
  51.             {
  52.                 m_trapmanager.GetTrap(m_selectedtrap).UseThisTrap(false);
  53.                 m_trapmanager.GetTrap(newtrapindex).UseThisTrap(true);
  54.  
  55.                 m_selectedtrap = newtrapindex;
  56.             }
  57.         }
  58.  
  59.         if (Input.GetKeyDown(player_previoustrapkey))
  60.         {
  61.             int newtrapindex = m_trapmanager.GetPreviousTrap(m_selectedtrap);
  62.  
  63.             if(newtrapindex != m_selectedtrap)
  64.             {
  65.                 m_trapmanager.GetTrap(m_selectedtrap).UseThisTrap(false);
  66.                 m_trapmanager.GetTrap(newtrapindex).UseThisTrap(true);
  67.  
  68.                 m_selectedtrap = newtrapindex;
  69.             }
  70.         }
  71.  
  72.         transform.position = m_activationposition[m_selectedtrap].position;
  73.  
  74.         if (m_trapmanager.GetTrap(m_selectedtrap).PlayerMayPress())
  75.         {
  76.             if (Input.GetKeyDown(player_activatetrapkey))
  77.             {
  78.                 m_trapmanager.ActivateTrap(m_selectedtrap);
  79.             }
  80.         }
  81.     }
  82. }
RAW Paste Data