FlyBird
< 返回列表时间: 2020-05-03来源:OSCHINA
游戏开始 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class StartGame : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetMouseButton(0)) { SceneManager.LoadScene(1); } } }
PipeCollision using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PipeCollision : MonoBehaviour { private void OnCollisionEnter(Collision collision) { if(collision.gameObject.tag == "Player") { this.GetComponent<AudioSource>().Play(); SceneManager.LoadScene(0); } } // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
摄像机跟随 using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFllow : MonoBehaviour { public GameObject bird; // Use this for initialization void Start () { } // Update is called once per frame void Update () { Vector2 birdPosition = bird.transform.position; float posY = birdPosition.y; if(posY > 2) { posY = 2; } else if (posY < -2) { posY = -2; } this.transform.position = new Vector3(birdPosition.x + 9f, birdPosition.y, transform.position.z); } }
移动碰撞 using System.Collections; using System.Collections.Generic; using UnityEngine; public class MoveTrigger : MonoBehaviour { public Transform currentBG; public Pipe p1; public Pipe p2; private void OnTriggerEnter(Collider other) { if(other.gameObject.tag == "Player") { Transform firstBG = GameManager._instance.lastBG; currentBG.position = new Vector3(firstBG.position.x + 10, currentBG.position.y, currentBG.position.z); GameManager._instance.lastBG = currentBG; p1.RandomPosition(); p2.RandomPosition(); } } // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
游戏控制 using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameManager : MonoBehaviour { public Transform lastBG; public static GameManager _instance; public int score = 0; // Use this for initialization private void Awake() { _instance = this; } void Start () { } // Update is called once per frame void Update () { } }
小鸟 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Bird : MonoBehaviour { public float timer; public int frameCount = 0; public int frameNumber = 10; public float birdSpeed = 5.0f; // Use this for initialization void Start () { this.GetComponent<Rigidbody>().velocity = new Vector3(birdSpeed, 0, 0); } // Update is called once per frame void Update () { timer += Time.deltaTime; if (timer >= 1.0f / frameNumber) { frameCount = (frameCount + 1) % 3; timer = 0; this.GetComponent<Renderer>().material.SetTextureOffset("_MainTex", new Vector2(0.333f * frameCount, 0)); } if(Input.GetMouseButton(0)) { Vector3 vel = this.GetComponent<Rigidbody>().velocity; this.GetComponent<Rigidbody>().velocity = new Vector3(3, 3, vel.z); this.GetComponent<AudioSource>().Play(); } } }
录屏文件
链接:https://pan.baidu.com/s/1rze-ZFX3jDZjwmcWo4cd6Q
提取码:z2t6
热门排行