Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ShootingProjectileScript : MonoBehaviour {
  5.  
  6.     public GameObject muzzle;
  7.     public Rigidbody projectile;
  8.     public float speed;
  9.     public Vector3 muzzlePos;
  10.     public Vector3 projectilePos;
  11.  
  12.     // Use this for initialization
  13.     void Start () {
  14.  
  15.     }
  16.    
  17.     // Update is called once per frame
  18.     void Update () {
  19.  
  20.         muzzlePos = transform.position;
  21.  
  22.         if (Input.GetMouseButtonDown(0))
  23.         {
  24.             Rigidbody clone;
  25.             clone = Instantiate(projectile, muzzlePos, transform.rotation) as Rigidbody;
  26.             clone.velocity = transform.TransformDirection(Vector3.forward * 10);
  27.  
  28.             Object.Destroy(projectile, 2.0f);
  29.            
  30.         }
  31.    
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement