Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Mar 14, 2014 at 12:01 PM by Benproductions1 for the following reason:

Not technical or specific.

avatar image
0
Question by Crumpet · Mar 14, 2014 at 11:09 AM · raycastingbulletgunfirereload

How can I shooting script c#?

Hey, I'm new to programming and I created a script to make my gun reload and add bullets maybe not the best way of doing this but it's how I decided to do it from my head without tutorials or anything. Anyway what I wanted to do was actually make my gun shoot, the bullets go down and all it just doesn't fire or anything. I have never used raycasting so I'd like to implement this into my script and was hoping someone could help me with that. Also sorry, I didn't do commenting on my script to show what's going on D: hopefully you people can just figure that out... also I am using c#

 using UnityEngine;
 using System.Collections;
 
 public class NewBehaviourScript : MonoBehaviour
 {
     public bool outofammo;
     public int bullets = 7;
     public GameObject deagle;
     public float time = 1;
     public float firerate = 1;
     public bool fired = false;
     public bool Cannotfire = false;
     public bool timedown;
 
     void Update ()
     {
             if (Input.GetKeyDown(KeyCode.R) && bullets < 7)
             {
                 deagle.animation.Play ("Reload");
                 bullets = 7;
             }
 
             if (Input.GetButtonDown("Fire1"))
             {
                 timedown = true;
 
                 if (bullets == 0)
                 {
                     bullets = 7;
                     outofammo = true;
                     timedown = false;
                 }
                 else 
                     outofammo = false;
 
                 if (outofammo == true)
                 {
                     deagle.animation.Play ("Reload");
                 }
 
             }
             
             if (timedown == true) 
             {
                 time = (time - (firerate *Time.deltaTime));
                 if (time <= 0)
                 {
                     bullets = bullets -1;
                     fired = true;
                     timedown = false;
                     time = 1f;
                     fired = false;
                 }
             }
             
             if (fired == true)
                 time = 1;
     }
 }
Comment
Add comment · Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Mar 14, 2014 at 11:58 AM 0
Share

To find how raycasts work look at the documentation. Otherwise this question is not specific enough to answer. There are many (infinite?) ways of "shooting" a "bullet".

avatar image Crumpet · Mar 14, 2014 at 12:35 PM 1
Share

I was looking for a way to implement the raycasting for the bullet, I don't $$anonymous$$d how it's done I've looked at the documents saying how to do it http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html but I'm asking how I would implement it into this script that I've created. I also have looked up tutorials, which usually just end up being in javascript which I would prefer not to use. Will I have to recreate this post if I would like to actually have people help me?

avatar image Crumpet · Mar 14, 2014 at 12:59 PM 1
Share

There are many ways of "shooting" a "bullet" as I said "I have never used raycasting so I'd like to implement this into my script and was hoping someone could help me with that." I'd like to use raycasting obviously. yes, there are many ways to make a bullet shoot, I was just looking for one of those ways. People do look at the documentation it just doesn't help for example

 // Raycast up to 100 meters down

 function Update () {
     var hit : RaycastHit;
     if (Physics.Raycast (transform.position, -Vector3.up, hit, 100.0)) {
         var distanceToGround = hit.distance;
     }
 }

this is one of the ways it recommends to do it, however this does not tell me how I would put this in my script. I may not have been technical enough but you really don't understand the situation without reading through the post properly. $$anonymous$$aybe I didn't mention some of this, but you could post a question ins$$anonymous$$d? maybe discuss how I wanted to make it work even? if I was new to this and had no idea what raycasting was and I wanted to make a bullet shoot you would help them by providing details about how you can do it would you not?

I am not trying to be smart or anything but it seems to me like you just deny people's posts for simple reasons such as this. So please, quit blocking peoples posts for simple reasons that could be solved in a simple answer. I am not here to argue, I'm here for help from other people. Thank you

avatar image Benproductions1 · Mar 14, 2014 at 12:59 PM 0
Share

There's a certain point in your script where you want the "bullet" to be "fired", since it's your script, you should know where that point is. At that point "implement" whatever kind of "firing" of "bullets" you want.

Also the difference between C# and UnityScript is no $$anonymous$$ute, it's really easy to follow tutorials or other pieces of code in either language (even Boo is pretty easy to understand).

avatar image VioKyma · Mar 15, 2014 at 12:00 AM 2
Share

@Crumpet The issue with your question is that you never actually tried it yourself. Go and try it as best you can, using the documentation as a guide. If you get stuck on SPECIFICS, then ask about those. Your question and others like it are essentially saying "Please write some code for me because I don't know how".

If you tried, and got errors, then post the code you tried, post the errors you got, and we will be very happy to help with that.

Show more comments

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

c# weapon shooting script using raycasting help 1 Answer

Best way to make a gun? 1 Answer

How do shoot a bullet when the right button is clicked? 1 Answer

Help on a pick up/reload script 3 Answers

Setting bullet instansiate direction? help? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges