Sure! Here's a basic script for a Flappy Bird game in Unity: \n\nC#\nusing UnityEngine;\n\npublic class FlappyBird : MonoBehaviour\n{\n public float jumpForce = 5f;\n public float gravity = 1f;\n\n private Rigidbody2D rb;\n private bool isDead = false;\n\n void Start()\n {\n rb = GetComponent<Rigidbody2D>();\n }\n\n void Update()\n {\n // Check for player input to make the bird jump\n if (Input.GetMouseButtonDown(0) && !isDead)\n {\n rb.velocity = Vector2.up * jumpForce;\n }\n\n // Apply gravity to the bird\n rb.velocity += Vector2.down * gravity;\n\n // Check if the bird hits the ground\n if (transform.position.y <= -4.5f)\n {\n Die();\n }\n }\n\n void Die()\n {\n isDead = true;\n // Add any necessary code for game over or restart the level\n }\n\n void OnTriggerEnter2D(Collider2D other)\n {\n // Check if the bird passes through the pipes\n if (other.CompareTag("Pipe"))\n {\n // Add score or any other necessary action\n }\n }\n}\n\n\nThis script includes basic functionality such as making the bird jump, applying gravity, detecting collisions with the ground, and triggering events when passing through pipes. You may need to modify it based on your specific requirements and game design.


原文地址: https://www.cveoy.top/t/topic/pObB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录