Advertisement
Guest User

Untitled

a guest
Feb 12th, 2017
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Shoot : MonoBehaviour
  6. {
  7.     public KeyCode shootKey = KeyCode.F;
  8.     public GameObject projectile;
  9.     public float shootForce;
  10.  
  11.     // Use this for initialization
  12.     void Start () {
  13.        
  14.     }
  15.    
  16.     // Update is called once per frame
  17.     void Update ()
  18.     {
  19.         if (Input.GetKeyDown(shootKey))
  20.         {
  21.             GameObject shot = GameObject.Instantiate(projectile, transform.position, transform.rotation);
  22.             shot.GetComponent<Rigidbody>().AddForce(transform.forward * shootForce);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement