Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public BasicNPCPrototype NPCPrototype;
- private bool nearNPC = false;
- public bool facingRight;
- public bool facingUp;
- public GameObject RightCollider;
- public GameObject LeftCollider;
- public GameObject TopCollider;
- public GameObject BottomCollider;
- // Use this for initialization
- protected override void Start()
- {
- base.Start();
- }
- // Update is called once per frame
- protected override void Update()
- {
- // Call the GetInput Function
- GetInput();
- // Call the CheckIfNear function
- CheckIfNear();
- // Call teh CheckDirection function
- CheckDirection();
- // Call the DisableInteractionColliders function
- DisableInteractionColliders();
- // 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
- base.Update();
- }
- void GetInput()
- {
- // If the player is active (playerActive is a protected bool in the "Character" script)
- if(playerActive)
- {
- direction = Vector2.zero;
- // Get the horizontal Axis and put in the X value of "direction"
- direction.x = Input.GetAxisRaw("Horizontal");
- // Get the Vertical Axis and put in the Y value of "direction"
- direction.y = Input.GetAxisRaw("Vertical");
- }
- }
- void CheckDirection()
- {
- if (direction.x > 0)
- {
- facingRight = true;
- facingUp = false;
- }
- else if (direction.x < 0)
- {
- facingRight = false;
- facingUp = false;
- }
- if (direction.y > 0) // && !facingRight)
- {
- facingUp = true;
- facingRight = false;
- }
- else if (direction.y < 0) // && !facingRight)
- {
- facingUp = false;
- facingRight = false;
- }
- }
- void DisableInteractionColliders()
- {
- // WIP
- if(facingRight)
- {
- RightCollider.SetActive(true);
- LeftCollider.SetActive(false);
- TopCollider.SetActive(false);
- BottomCollider.SetActive(false);
- } else if(!facingRight)
- {
- LeftCollider.SetActive(true);
- RightCollider.SetActive(false);
- TopCollider.SetActive(false);
- BottomCollider.SetActive(false);
- }
- else if(facingUp)
- {
- TopCollider.SetActive(true);
- RightCollider.SetActive(false);
- LeftCollider.SetActive(false);
- BottomCollider.SetActive(false);
- } else if(!facingUp)
- {
- BottomCollider.SetActive(true);
- RightCollider.SetActive(false);
- LeftCollider.SetActive(false);
- TopCollider.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment