Advertisement
Guest User

PlayerMovement

a guest
Jan 12th, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour
  6. {
  7.     public float acceleration;
  8.     private Rigidbody rb;
  9.     private bool isSwipe = true;
  10.     public GameObject winPanel;
  11.  
  12.     void Start()
  13.     {
  14.         SwipeController.SwipeEvent += CheckInput;
  15.         rb = gameObject.GetComponent<Rigidbody>();
  16.     }
  17.  
  18.     void CheckInput(SwipeController.SwipeType type)
  19.     {
  20.         if (type == SwipeController.SwipeType.UP && isSwipe == true)
  21.         {
  22.             rb.AddForce(new Vector3(0, 0, -1).normalized * acceleration, ForceMode.Impulse);
  23.             Debug.Log("UP");
  24.             isSwipe = false;
  25.             StartCoroutine(time());
  26.         }
  27.  
  28.         else if (type == SwipeController.SwipeType.DOWN && isSwipe == true)
  29.         {
  30.             rb.AddForce(new Vector3(0, 0, 1).normalized * acceleration, ForceMode.Impulse);
  31.             Debug.Log("DOWN");
  32.             isSwipe = false;
  33.             StartCoroutine(time());
  34.         }
  35.  
  36.         if (type == SwipeController.SwipeType.LEFT && isSwipe == true)
  37.         {
  38.             rb.AddForce(new Vector3(1, 0, 0).normalized * acceleration, ForceMode.Impulse);
  39.             Debug.Log("LEFT");
  40.             isSwipe = false;
  41.             StartCoroutine(time());
  42.         }
  43.         if (type == SwipeController.SwipeType.RIGHT && isSwipe == true)
  44.         {
  45.             rb.AddForce(new Vector3(-1, 0, 0).normalized * acceleration, ForceMode.Impulse);
  46.             Debug.Log("RIGHT");
  47.             isSwipe = false;
  48.             StartCoroutine(time());
  49.         }
  50.     }
  51.     IEnumerator time()
  52.     {
  53.         yield return new WaitForSeconds(0.7f);
  54.         isSwipe = true;
  55.     }
  56.  
  57.     private void OnTriggerEnter(Collider other)
  58.     {
  59.         if(other.gameObject.tag == "finish")
  60.         {
  61.             winPanel.SetActive(true);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement