NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Touch screen swipe functionality.

Code (CSharp):
if (Input.touchCount > 0)
{

Touch touch = Input.GetTouch(0); // First touch

if (touch.phase == TouchPhase.Began)
{

startTime = Time.time; // Storing start time
startPos = touch.position; // storing start position

}

else if (touch.phase == TouchPhase.Ended) // Touch ended
{
endTime = Time.time;
endPos = touch.position;

swipeDistance = (endPos - startPos).magnitude;
swipeTime = endTime - startTime;

if (swipeTime < maxTime && swipeDistance > minSwipeDist)
{

Swipes();


}



}

}

The Swipes Function.
Code (CSharp):
void Swipes()
{

Vector2 distance = endPos - startPos;

if (Mathf.Abs(distance.x) > Mathf.Abs(distance.y))
{
Debug.Log("Horizontal Swipe");

if (distance.x > 0)
{


Debug.Log("Right Swipe");



if (flip == true)

{

if (playerPos < 2)
{

transform.Translate(new Vector3(0f, 0f, -moveDistance)); // move right
playerPos++;
}



}

else

{

if (playerPos < 2)
{

transform.Translate(new Vector3(0f, 0f, moveDistance)); // move right while flipped
playerPos++;
}



}

}


if (distance.x < 0)
{
Debug.Log(" Left Swipe");



if (flip == true)

{

if(playerPos > 0)
{
transform.Translate(new Vector3(0f, 0f, moveDistance)); // move left
playerPos--;
}




}

else

{

if (playerPos >0)
{
transform.Translate(new Vector3(0f, 0f, -moveDistance)); // move left while flipped
playerPos--;

}



}
















}



}

else if (Mathf.Abs(distance.x) < Mathf.Abs(distance.y))
{
Debug.Log(" Vertical Swipe");

if (distance.y > 0)
{
Debug.Log("Up Swipe");

if (Grounded())
{


myRigidbody.velocity = new Vector3(myRigidbody.velocity.x, JumpForce);



}




}

if (distance.y < 0)
{
Debug.Log(" Down Swipe");

if (!Grounded())
{


StartCoroutine(RotateAround(Vector3.left, 180.0f, 0.3f));



if (flip == false)
{

flip = true;
}

else
flip = false;

}





}


}



}


Coroutine for the cube flip
Code (CSharp):
IEnumerator RotateAround(Vector3 axis, float angle, float duration)
{
float elapsed = 0.0f;
float rotated = 0.0f;
while (elapsed < duration)
{
float step = angle / duration * Time.deltaTime;
transform.RotateAround(transform.position, axis, step);
elapsed += Time.deltaTime;
rotated += step;
yield return null;
}
transform.RotateAround(transform.position, axis, angle - rotated);
}


This code increases the movement speed over time
Code (CSharp):

if (transform.position.x > speedCount)
{
speedCount += speedIncrease;

speedIncrease = speedIncrease * speedMultiplier; // Milestones further apart

moveSpeed = moveSpeed * speedMultiplier;
}


This is my game manager script. This code restarts the level. Putting the player back to where the player started insteading of reloading the scene.

Code (CSharp):
using UnityEngine;
using System.Collections;


public class GameManager : MonoBehaviour {



public PlayerController1 thePlayer;
private Vector3 PlayerStartPoint;

private ScoreManager theScoreManager;



void Start () {

PlayerStartPoint = thePlayer.transform.position;

theScoreManager = FindObjectOfType<ScoreManager>();

} // start End


void Update () {


} // update end
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.