Answers for "gun script unity"

C#
0

gun script unity

using UnityEngine;
using System.Collections;
 
public class ShootDemo : MonoBehaviour {
    public Rigidbody projectile;
    public float speed = 20;
 
    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update () {
        if (Input.GetButtonDown("fire1"))
        {
            Rigidbody instantiatedProjectile = Instantiate(projectile,transform.position,transform.rotation)
                as Rigidbody;
 
            instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
        }
    }
}
Posted by: Guest on July-06-2021

C# Answers by Framework

Browse Popular Code Answers by Language