Код основа для шутера в Unity
// PlayerController.cs
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Transform bulletSpawnPoint;
public GameObject bulletPrefab;
public float bulletForce = 10f;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
// Instantiate a new bullet
GameObject bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
// Apply force to the bullet
Rigidbody bulletRigidbody = bullet.GetComponent<Rigidbody>();
bulletRigidbody.AddForce(bulletSpawnPoint.forward * bulletForce, ForceMode.Impulse);
// Destroy the bullet after a certain time
Destroy(bullet, 2f);
}
}
}
Около минуты
8 августа 2023