Paso 5: Permite crear pájaros flappy en nuestra unidad :)
para hacer pájaros flappy seguí un tutorial en youtube que está muy claro y agradable de principiante
tutorial unidad de pájaros Flappy
pero para este tutorial todo lo que necesitas es tener un sprite de pájaro y simplemente conecte el siguiente script que
using UnityEngine;using System.Collections; using System.IO.Ports; public class Bird : MonoBehaviour { public AudioSource player; public Vector3 gravity; public Vector3 jumpVelocity; public int rotationspeed; private bool didFlap; private Vector3 velocity; private SerialPort port; // Use this for initialization void Start () { port = new SerialPort( + "COM11", 9600); port.Open(); port.ReadTimeout = 25; didFlap = false; velocity = Vector3.zero; } void Update() { if (port.IsOpen) { try { float value = port.ReadByte(); if (value > 0) { value = Mathf.Clamp(value, 0,2); didFlap = true; jumpVelocity.y = value; } } catch (System.Exception) { } } if (Input.GetKeyDown(KeyCode.Space)) { didFlap = true; } } // Update is called once per frame void FixedUpdate () { velocity -= gravity * Time.deltaTime; if (didFlap) { didFlap = false; if (!player.isPlaying) { player.Play(); } if (velocity.y <0) { velocity = Vector3.zero; } velocity += jumpVelocity; } transform.position += velocity*Time.deltaTime; float angle = 0; if (velocity.y < 0) { angle=Mathf.Lerp(0, -90, -velocity.y/3); } transform.rotation = Quaternion.Euler(0f, 0f, angle); } }