Gamegenorator

Player Script

Mar 24th, 2019
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1.  public BasicNPCPrototype NPCPrototype;
  2.     private bool nearNPC = false;
  3.  
  4.     public bool facingRight;
  5.     public bool facingUp;
  6.  
  7.     public GameObject RightCollider;
  8.     public GameObject LeftCollider;
  9.     public GameObject TopCollider;
  10.     public GameObject BottomCollider;
  11.  
  12.     // Use this for initialization
  13.     protected override void Start()
  14.     {
  15.         base.Start();
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     protected override void Update()
  20.     {
  21.         // Call the GetInput Function
  22.         GetInput();
  23.  
  24.         // Call the CheckIfNear function
  25.         CheckIfNear();
  26.  
  27.         // Call teh CheckDirection function
  28.         CheckDirection();
  29.  
  30.         // Call the DisableInteractionColliders function
  31.         DisableInteractionColliders();
  32.  
  33.         // This needs to be here because the Override normally would override the Character Update function so we have this here to tell the Character Update function to go
  34.         base.Update();
  35.     }
  36.  
  37.     void GetInput()
  38.     {
  39.         // If the player is active (playerActive is a protected bool in the "Character" script)
  40.         if(playerActive)
  41.         {
  42.             direction = Vector2.zero;
  43.  
  44.             // Get the horizontal Axis and put in the X value of "direction"
  45.             direction.x = Input.GetAxisRaw("Horizontal");
  46.             // Get the Vertical Axis and put in the Y value of "direction"
  47.             direction.y = Input.GetAxisRaw("Vertical");
  48.         }    
  49.     }
  50.     void CheckDirection()
  51.     {
  52.         if (direction.x > 0)
  53.         {
  54.             facingRight = true;
  55.             facingUp = false;
  56.         }
  57.         else if (direction.x < 0)
  58.         {
  59.             facingRight = false;
  60.             facingUp = false;
  61.         }
  62.  
  63.         if (direction.y > 0) // && !facingRight)
  64.         {
  65.             facingUp = true;
  66.             facingRight = false;
  67.         }
  68.         else if (direction.y < 0) // && !facingRight)
  69.         {
  70.             facingUp = false;
  71.             facingRight = false;
  72.         }
  73.  
  74.     }
  75.     void DisableInteractionColliders()
  76.     {
  77.         // WIP
  78.         if(facingRight)
  79.         {
  80.             RightCollider.SetActive(true);
  81.             LeftCollider.SetActive(false);
  82.             TopCollider.SetActive(false);
  83.             BottomCollider.SetActive(false);
  84.         } else if(!facingRight)
  85.         {
  86.             LeftCollider.SetActive(true);
  87.             RightCollider.SetActive(false);
  88.             TopCollider.SetActive(false);
  89.             BottomCollider.SetActive(false);
  90.         }
  91.  
  92.          else if(facingUp)
  93.         {
  94.             TopCollider.SetActive(true);
  95.             RightCollider.SetActive(false);
  96.             LeftCollider.SetActive(false);
  97.             BottomCollider.SetActive(false);
  98.         } else if(!facingUp)
  99.         {
  100.             BottomCollider.SetActive(true);
  101.             RightCollider.SetActive(false);
  102.             LeftCollider.SetActive(false);
  103.             TopCollider.SetActive(false);
  104.         }
  105.     }
Advertisement
Add Comment
Please, Sign In to add comment