Untitled
unknown
plain_text
2 years ago
790 B
12
Indexable
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f;
public GameObject bulletPrefab;
public Transform firePoint;
private void Update()
{
// Player movement
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(horizontalInput, 0f, verticalInput) * moveSpeed * Time.deltaTime;
transform.Translate(movement);
// Player shooting
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
// Add code here for bullet behavior, like setting speed and damage
}
}Editor is loading...
Leave a Comment