0% found this document useful (0 votes)
10 views6 pages

Deekshitha Namadevan Week 8 Assignment

Uploaded by

deekshithadeva30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Deekshitha Namadevan Week 8 Assignment

Uploaded by

deekshithadeva30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

GAMING ASSIGNMENT WEEK 8

Create Events

● Create an empty in hierarchy panel and name it as event

● create a c# script named events

● Events will help in the replay and quit option function

● The event code is :

using UnityEngine.SceneManagement;

using UnityEngine;

public class events : MonoBehaviour

public void ReplayGame()

SceneManager.LoadScene("SampleScene");

public void QuitGame ()

Application.Quit();

}
● Now check the inspector in the game over panel

● Now drag the script to the replay and quit button

● And uncheck the game over

• To create tap to start button, in hierarchy panel Right click and

select UI and select Text and the game over panel created .

• And name this text as starting text /start text, change the

height and width as per the requirements.

• Then select windows and select animation and click

animation at 0 – 1, at 30 -1.5, at 60 – 1.

• Press record button, now we can resize the scale value to

make our text like breathing.

● For swipe control of the game change your player

controller code into

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class swipeManager : MonoBehaviour

public static bool tap, swipeLeft, swipeRight, swipeUp,

swipeDown;

private bool isDraging = false;

private Vector2 startTouch, swipeDelta;


private void Update()

tap = swipeDown = swipeUp = swipeLeft = swipeRight

= false;

#region Standalone Inputs

if (Input.GetMouseButtonDown(0))

tap = true;

isDraging = true;

startTouch = Input.mousePosition;

else if (Input.GetMouseButtonUp(0))

isDraging = false;

Reset();

#endregion

#region Mobile Input

if (Input.touches.Length > 0)

if (Input.touches[0].phase == TouchPhase.Began)

tap = true;

isDraging = true;

startTouch = Input.touches[0].position;

}
else if (Input.touches[0].phase ==

TouchPhase.Ended || Input.touches[0].phase ==

TouchPhase.Canceled)

isDraging = false;

Reset();

#endregion

//Calculate the distance

swipeDelta = Vector2.zero;

if (isDraging)

if (Input.touches.Length < 0)

swipeDelta = Input.touches[0].position -

startTouch;

else if (Input.GetMouseButton(0))

swipeDelta = (Vector2)Input.mousePosition -

startTouch;

//Did we cross the distance?

If (swipeDelta.magnitude > 100)

//Did we cross the distance?


if (swipeDelta.magnitude > 100)

//Which direction?

float x = swipeDelta.x;

float y = swipeDelta.y;

if (Mathf.Abs(x) > Mathf.Abs(y))

//Left or Right

if (x < 0)

swipeLeft = true;

else

swipeRight = true;

else

//Up or Down

if (y < 0)

swipeDown = true;

else

swipeUp = true;

Reset();

private void Reset()

{
startTouch = swipeDelta = Vector2.zero;

isDraging = false;

● Now drag the code and attach it the player and check the Output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy