using UnityEngine; using System.Collections; public class ShooterGame : MonoBehaviour { public GameObject bulletPrefab; public GameObject targetPrefab; public float bulletSpeed = 10f; public float spawnTime = 2f; private float timeSinceLastSpawn = 0f; private int score = 0; void Update() { // Shoot a bullet when mouse is clicked if (Input.GetMouseButtonDown(0)) { ShootBullet(); } // Spawn targets timeSinceLastSpawn += Time.deltaTime; if (timeSinceLastSpawn >= spawnTime) { SpawnTarget(); timeSinceLastSpawn = 0f; } } void ShootBullet() { // Get shooter position Vector3 shooterPos = transform.position; GameObject bullet = Instantiate(bulletPrefab, shooterPos, Quaternion.identity); Rigidbody2D rb = bullet.GetComponent(); rb.velocity = Vector2.up * bulletSpeed; } void SpawnTarget() { float randomX = Random.Range(-5f, 5f); Vector3 spawnPos = new Vector3(randomX, 5f, 0); Instantiate(targetPrefab, spawnPos, Quaternion.identity); } public void HitTarget() { score++; Debug.Log("Score: " + score); } }