- Home /
Swipe not Responding
Hello so i just made a Swipe scripts [C#] and it looks like it should be working,no errors no nothing.When i try to implement swipe mechanics to my Player Movement Script it just doesn't work please fix my code i'm no expert please.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bounce : MonoBehaviour {
public Swipe swipeControls;
public GameObject key;
float lerpTime ;
float currentLerpTime;
float perc = 1;
Vector3 startPos;
Vector3 endPos;
bool FirstInput;
public bool justJump;
// Update is called once per frame
void Update ()
{
if(swipeControls.SwipeLeft || swipeControls.SwipeRight || swipeControls.SwipeUp || swipeControls.SwipeDown)
{
if(perc == 1)
{
lerpTime = 1;
currentLerpTime = 0;
FirstInput = true;
justJump = true;
}
}
startPos = gameObject.transform.position;
if (swipeControls.SwipeRight && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
}
if (swipeControls.SwipeLeft && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
}
if (swipeControls.SwipeUp && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
}
if (swipeControls.SwipeDown && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z - 1);
}
if (FirstInput == true)
{
currentLerpTime += Time.deltaTime * 5;
perc = currentLerpTime / lerpTime;
gameObject.transform.position = Vector3.Lerp(startPos, endPos, perc);
}
if(perc > 0.8)
{
perc = 1;
}
if (Mathf.Round(perc) == 1)
{
justJump = false;
}
}
void OnTriggerEnter(Collider myTrigger)
{
if(myTrigger.gameObject.name == "Enemy")
{
key.SetActive(false);
}
}
}
Comment