Advertisement
Guest User

shootProjectile.cs

a guest
Apr 5th, 2020
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace MAGD272Demo
  6. {
  7.     public class shootProjectile : MonoBehaviour
  8.     {
  9.         public GameObject projectile;
  10.         public Transform shootPoint;
  11.  
  12.         [SerializeField] private KeyCode shootButton;
  13.  
  14.         // Update is called once per frame
  15.         void Update()
  16.         {
  17.             if (Input.GetKeyDown(shootButton))
  18.             {
  19.                 if (projectile == null)
  20.                 {
  21.                     Debug.Log("No projectile Set");
  22.                 }
  23.                 else
  24.                 {
  25.                     // the direction of the instantiation is linked to the object's transfom.rotation
  26.                     Instantiate(projectile, shootPoint.position, transform.rotation);
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement