fps2
작성자 : 진영훈
작성일 : 2023-12-08 13:53
using UnityEngine;
public class PlayerShooting : MonoBehaviour
{
public GameObject bulletPrefab;
public Transform firePoint;
public float bulletSpeed = 10f;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
Rigidbody bulletRb = bullet.GetComponent<Rigidbody>();
bulletRb.AddForce(firePoint.forward * bulletSpeed, ForceMode.VelocityChange);
}
}