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 /
avatar image
0
Question by Fyrepixel · Dec 14, 2013 at 01:07 AM · gunshoothowmakingunanswered

Making a gun shoot WELL?

Hello, I've been using unity for a while, and I know basic scripting, although I'm still learning. I know that I'm going to get yelled at to go watch tutorials and whatnot, and to learn scripting, but I need a quick answer. I just want to complete the shooting and guns and core of the game, so I can focus on the story. All the tutorials I've watched make the bullet spawn at the wrong place, and they're all to complicated for such a simple thing. Below is the code for another Unity answer, but I get an error: Not a valid Identifier: 'nBullate'.

 var bullet : GameObject;
 var spawnPoint : Transform;
  
 function Update () {
     if(Input.GetKeyDown("mouse0")) {
        var nBullet = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation);
        nBullate.rigidbody.velocity = spawnPoint.TransformDirection(Vector3(0,0,100));
     }
 }

Please help me. I understant everything in this script except for the nBullate part. Thanks in advance!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Dec 14, 2013 at 01:09 AM

You've misspelled 'nBullet' on line 7...you have an extra 'a' in the name. Plus on line 6, you need to add 'as GameObject':

 var nBullet = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as GameObject;
Comment
Add comment · Show 4 · Share
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 alienbaby · Dec 14, 2013 at 01:20 AM 0
Share

Just wondering; I would tend to use

var nBullet:GameObject = Instantiate(bullet,spawnPoint.position,spawnPoint.rotation);

Is there any difference between the two?

avatar image robertbu · Dec 14, 2013 at 01:40 AM 0
Share

@alienbaby - For Javascript I don't know. They don't have prefix casting. There is casting going on here because Instantiate() returns an Object, not a GameObject. For C#, see:

http://answers.unity3d.com/questions/27118/what-is-the-difference-between-prefix-casting-type.html

avatar image Fyrepixel · Dec 14, 2013 at 01:57 AM 0
Share

It didn't make my gun shoot. I assigned a bullet GameObject with a box collider and rigidbody. I also put an empty gameobject at the tip of my gun and parented it to the gun, then I dragged the empty gameobject to the transform. Please tell me if I did anything wrong. P.S. I assigned the script directly to my gun.

Also, don't reply that this isn't a forum and that I shouldn't reply.

avatar image robertbu · Dec 14, 2013 at 03:20 AM 0
Share

Also, don't reply that this isn't a forum and that I shouldn't reply.

Not sure what this means. Providing comments when you tried to use a solution is just fine. What you should not (and have not done) is use an 'Answer' field to add comments.

As for your code, there is no key called 'mouse0'. Replace line 5 with:

 if(Input.Get$$anonymous$$ouseButtonDown(0))

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Gun and hand animation tutorial! 2 Answers

Shooting. Bullet floats and sprays 1 Answer

Problems with a shooting script 1 Answer

How let my machinegun(like the deathmachine in cod black ops) to shoot a projectile one after the other?? 2 Answers

Bullets will not fire forwards 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