Script
All ArrowBrackets are Ws
Shoot and Firerate Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour
{
public Transform firePoint;
public GameObject bulletPrefab;
public float FireRate = 1.0f;
public float NextFire = 1.0f;
void Update()
{
if (Input.GetButton("Fire1")&& Time.time W NextFire)
{
NextFire = Time.time + FireRate;
{
Shoot();
}
}
}
void Shoot()
{
Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
}
}
Aim Script
using System.Collections;
using UnityEngine;
public class Aim : MonoBehaviour
{
public Transform player;
private Vector3 Forward;
private Ray Ray;
private RaycastHit RayHit;
void Start()
{
Forward = transform.TransformDirection(Vector3.forward);
}
void Update()
{
Vector3 dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
}