Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BirdScript : MonoBehaviour
- {
- public Rigidbody2D myRigidbody;
- public float flapStrength;
- public LogicScript logic;
- public bool birdIsAlive = true;
- // Start is called before the first frame update
- void Start()
- {
- logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space) && birdIsAlive)
- {
- myRigidbody.velocity = Vector2.up * flapStrength;
- }
- }
- private void OnCollisionEnter2D(Collision2D collision)
- {
- logic.gameOver();
- birdIsAlive = false;
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PipeMoveScript : MonoBehaviour
- {
- public float moveSpeed = 5;
- public float deadZone = -45;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (transform.position.x > deadZone)
- {
- Destroy(gameObject);
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PipeSpawnScript : MonoBehaviour
- {
- public GameObject pipe;
- public float spawnRate = 2;
- private float timer = 0;
- public float heightOffset = 10;
- // Start is called before the first frame update
- void Start()
- {
- spawnPipe();
- }
- // Update is called once per frame
- void Update()
- {
- if (timer < spawnRate)
- {
- timer = timer + Time.deltaTime;
- }
- else
- {
- spawnPipe();
- timer = 0;
- }
- }
- void spawnPipe()
- {
- float lowestPoint = transform.position.y - heightOffset;
- float highestPoint = transform.position.y + heightOffset;
- Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0), transform.rotation);
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PipeMiddleScript : MonoBehaviour
- {
- public LogicScript logic;
- // Start is called before the first frame update
- void Start()
- {
- logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
- }
- // Update is called once per frame
- void Update()
- {
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- if (collision.gameObject.layer == 3)
- {
- logic.addScore(1);
- }
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class LogicScript : MonoBehaviour
- {
- public int playerScore;
- public Text scoreText;
- public GameObject gameOverScreen;
- [ContextMenu("Increase Score")]
- public void addScore(int scoreToAdd)
- {
- playerScore = playerScore + scoreToAdd;
- scoreText.text = playerScore.ToString();
- }
- public void restartGame()
- {
- SceneManager.LoadScene(SceneManager.GetActiveScene().name);
- }
- public void gameOver()
- {
- gameOverScreen.SetActive(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement