i know this question has been asked before
how do i make my gun shoot it’s already a week i learning how to make my gun shoot but none work why ?
can i have a beginner tutorial of how to make a gun shoot in c#
thank you
i know this question has been asked before
how do i make my gun shoot it’s already a week i learning how to make my gun shoot but none work why ?
can i have a beginner tutorial of how to make a gun shoot in c#
thank you
Dont know, show us what you have already tried then we might be able to help.
Is this 2D or 3D, Top down, FPS, TPS…
Need more info.
Check this out (not my video)
it’s 3d fps
i’ll upload the file tmr it’s midnight here in hk
thanks
i tried it just now but i got error:face_with_spiral_eyes: : UnityException: Input Button fire1 is not setup.
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));
}
}
}
Thanks:sad:
You have to go to Edit → Project Settings → Input and add it yourself.
Edit, in this case change the “fire1” to uppercase might help.
Yes indeed, it should be Fire1
if (Input.GetButtonDown("Fire1"))
This should work:
using UnityEngine;
using System.Collections;
public class ShootDemo : MonoBehaviour
{
public Rigidbody projectile;
public float speed = 20;
// 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));
}
}
}
Thank you so much both of you!
it helped me alot!
Thanks.
nope i typed it in and it gave me hundreds of errors like: [‘;’ expected insert semicolon at end] [expecting EOF, found ‘;’] and [unexpected token: float]-[unexpected token: public
post the code you have then.
Hey, this script make my bullet go half way down the character. Is there anything I can do to fix it?
For those that are having problems. Here is a Asset that is has weapon models, enemies, weapon upgrades, and even pickups. I have started using it and it is really good.
HI I’m ttying to make a really awesome and exciting game in TPS how would I make animations, Gun fire, and enemy AI?
This is my script for C#. Try this.
Also, make sure you add a spawn point and rigidbody to your bullet prefab.
using UnityEngine;
using System.Collections;
public class ShootMissle : MonoBehaviour {
public GameObject spawnPoint;
public GameObject ExplosionPrefab;
public Rigidbody projectilePrefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Fire1"))
{
Rigidbody hitPlayer;
hitPlayer = Instantiate(projectilePrefab, transform.position, transform.rotation) as Rigidbody;
hitPlayer.velocity = transform.TransformDirection(Vector3.forward * 100);
// Physics.IgnoreCollision ( projectilePrefab.collider, transform.root.collider );
}
for(var i =0; i < Input.touchCount; ++i)
{
if(Input.GetTouch(i).phase == TouchPhase.Began )
{
Rigidbody clone;
clone = Instantiate(projectilePrefab, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * 200);
// Physics.IgnoreCollision ( projectilePrefab.collider, transform.root.collider );
}
}
}
}
Thank you people very muchfords for the scripts i am using to create “egglike” game known as great game.
Nice, sound awesome!
i am a beggnier and need to know where to put or place this code or on which game object . need help
:(
of gun shooting . i want a simple gun which shoot bullets
yo I’m making a game with a grid terrain and bit-style guns. itll be called Bit-Intruder
I tried your code (it is working) but the bullet is shooting up! how can i fix it thanks a lot!
try rotating the object that has the script applied to