-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduckMoves.cs
More file actions
45 lines (38 loc) · 1.08 KB
/
duckMoves.cs
File metadata and controls
45 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class duckMoves : MonoBehaviour
{
public float jumpForce = 2f;
public float forwardSpeed = 2f;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
forwardSpeed += (Time.deltaTime/20);
if(transform.position.y < -3.25 || transform.position.y > 3.25)
{
UnityEngine.SceneManagement.SceneManager.LoadScene("GameOver");
}
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
rb.velocity = Vector2.up * jumpForce;
}
}
rb.velocity = new Vector2(forwardSpeed, rb.velocity.y);
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Pipe")
{
// Restart the game
UnityEngine.SceneManagement.SceneManager.LoadScene("GameOver");
}
}
}