Kyle_Dev

Omnious Obstacles - PlayerController -> Traps

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