Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour
- {
- public float acceleration;
- private Rigidbody rb;
- private bool isSwipe = true;
- public GameObject winPanel;
- void Start()
- {
- SwipeController.SwipeEvent += CheckInput;
- rb = gameObject.GetComponent<Rigidbody>();
- }
- void CheckInput(SwipeController.SwipeType type)
- {
- if (type == SwipeController.SwipeType.UP && isSwipe == true)
- {
- rb.AddForce(new Vector3(0, 0, -1).normalized * acceleration, ForceMode.Impulse);
- Debug.Log("UP");
- isSwipe = false;
- StartCoroutine(time());
- }
- else if (type == SwipeController.SwipeType.DOWN && isSwipe == true)
- {
- rb.AddForce(new Vector3(0, 0, 1).normalized * acceleration, ForceMode.Impulse);
- Debug.Log("DOWN");
- isSwipe = false;
- StartCoroutine(time());
- }
- if (type == SwipeController.SwipeType.LEFT && isSwipe == true)
- {
- rb.AddForce(new Vector3(1, 0, 0).normalized * acceleration, ForceMode.Impulse);
- Debug.Log("LEFT");
- isSwipe = false;
- StartCoroutine(time());
- }
- if (type == SwipeController.SwipeType.RIGHT && isSwipe == true)
- {
- rb.AddForce(new Vector3(-1, 0, 0).normalized * acceleration, ForceMode.Impulse);
- Debug.Log("RIGHT");
- isSwipe = false;
- StartCoroutine(time());
- }
- }
- IEnumerator time()
- {
- yield return new WaitForSeconds(0.7f);
- isSwipe = true;
- }
- private void OnTriggerEnter(Collider other)
- {
- if(other.gameObject.tag == "finish")
- {
- winPanel.SetActive(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement