Advertisement
leomovskii

Weapon

Oct 5th, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.52 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Weapon : MonoBehaviour {
  4.  
  5.     public Rigidbody bullet;
  6.     public Transform aimPoint;
  7.     public float fireForce;
  8.     public float rejection;
  9.  
  10.     private void Update() {
  11.         if (Input.GetKeyDown(KeyCode.Space)) {
  12.             Rigidbody copy = Instantiate(bullet, aimPoint.position, Quaternion.identity);
  13.             Vector3 direction = aimPoint.forward;
  14.             direction.x += Random.Range(-rejection, rejection);
  15.             direction.y += Random.Range(-rejection, rejection);
  16.             copy.AddForce(direction * fireForce);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement