Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Steel598 · Jul 12, 2017 at 05:41 PM · bulletgun script

making my gun shoot...

My problem with my gun so far is the bullet. I know i need it to go out a distance and then go back to the gun, but doing that, is over my head. here is the code i saw and put on my bullet: using System.Collections; using System.Collections.Generic; using UnityEngine;

public class bulletscript : MonoBehaviour {

 var Bullet : Transform;
 var Spawn : Transform;


 function Update ()
 {
     if(Input.GetButtonDown("Fire1"))
     {
         Shoot();
     }
 }

 function Shot()
 {
     var pel = Instantiate(Bullet, Spawn.position, Spawn.rotation);
     pel.rigidbody.AddForce(transform.forward * 8000);

 }}

so the error it gives it the :'s in the beginning of the code, and I tried using ='s but I have no idea what i am doing. anyway, thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jinkata · Jul 12, 2017 at 06:08 PM

Looks like your file is a C# file and you've written your code in JavaScript.

Even with that fixed you're calling Shoot() but your function name is Shot()

Here's the C# equivalent:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;

 public class bulletscript : MonoBehaviour {

  public Transform Bullet;
  public Transform Spawn;

   void Update ()
   {
     if(Input.GetButtonDown("Fire1"))
     {
       Shoot();
     }
   }
   void Shoot()
   {
      var pel = Instantiate(Bullet, Spawn.position, Spawn.rotation);
      pel.rigidbody.AddForce(transform.forward * 8000);
   }
 }
Comment
Add comment · 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
0

Answer by Steel598 · Jul 12, 2017 at 06:34 PM

@Jinkata it said it is using obsolete api's... it is on line 20. is there another way to do that?

Comment
Add comment · Show 1 · 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 Jinkata · Jul 12, 2017 at 11:20 PM 0
Share

@Steel598 This should really be a comment rather than an answer, but it looks like this is due to the pel.rigidbody. Seems like the preferred method is to now use GetComponent so you would do something like this:

 pel.GetComponent<Rigidbody>().AddForce(transform.forward * 8000);

OR

 var rb = pel.GetComponent<Rigidbody>();
 rb.AddForce(transform.forward * 8000);

Either one will work.

https://docs.unity3d.com/2017.2/Documentation/ScriptReference/GameObject-rigidbody.html

avatar image
0

Answer by kikonavpash · Sep 19, 2017 at 07:31 PM

what buton on the keyboard is "fire 1" i dont know it

Comment
Add comment · Show 1 · 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 RoseTheArtDude · Oct 24, 2017 at 09:37 PM 0
Share

@kikonavpash go into Edit up on the top left then go down to project settings and then input then click on Fire1 and set your button if not already set its default is usually L$$anonymous$$B or left $$anonymous$$ouse Button.

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

71 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

i have too many bullets... 2 Answers

Need Help with Shooting Script c# 5 Answers

How to make a bullet spread 1 Answer

My bullet isn't facing the correct way when I shoot it out of my gun. Help! 0 Answers

Bullets aren't firing / Bullet holes not instantiating correctly 0 Answers


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