- Home /
Question by
Moonlads · Sep 13, 2017 at 10:51 PM ·
unity 5gameobjectswipeheight
Key Arrows into Swipe Input
Hello i have actually just got my game to the App Store so i was like why not make another one,here is my problem i want that when player swipes left,right,down it goes in that direction,i have setup that for key arrows but how do i set it for swipe? Here is my code:`
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Bounce : MonoBehaviour {
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(Input.GetButtonDown("up") || Input.GetButtonDown("down") || Input.GetButtonDown("right") || Input.GetButtonDown("left"))
{
if(perc == 1)
{
lerpTime = 1;
currentLerpTime = 0;
FirstInput = true;
justJump = true;
}
}
startPos = gameObject.transform.position;
if (Input.GetButtonDown("right") && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z);
}
if (Input.GetButtonDown("left") && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z);
}
if (Input.GetButtonDown("up") && gameObject.transform.position == endPos)
{
endPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1);
}
if (Input.GetButtonDown("down") && 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;
}
}
} `
Comment
Your answer
Follow this Question
Related Questions
Calling an Audio Source on one game object from a script on another game object..? 1 Answer
GameObject keeps acting like gameObject. 1 Answer
Script on multiple objects not working properly! 1 Answer
Changing alpha value of a canvas from a different game object 1 Answer
Function to assign gameobject components with parameter strings... 1 Answer