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 TheKnight · Jul 20, 2011 at 01:51 PM · javascriptfpsbeginnerfire

Shooter script

I am trying to do simple throwing of crates and seen this from tornado twins. Here is the script

 var speed = 3.0; var
  cratePrefab:Transform;
  
  function Update ()  {     
  // find out if a fire button is pressed
      if(Input.GetButtonDown("Fire1")){
          // create the prefab         
  var crate = Instantiate(cratePrefab,transform.position,Quaternion.identity);
          // add force to the prefab
          crate.Rigidbody.AddForce(transform.forward * 2000);
               } }

and it gets error : "Null Reference exception: Object Reference not set to an instance of an object."

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
0
Best Answer

Answer by aldonaletto · Jul 20, 2011 at 02:16 PM

You've wrote crate.Rigidbody while the correct is crate.rigidbody (Rigidbody is a type). The correct form is:

      crate.rigidbody.AddForce(transform.forward * 2000);
Remeber also that your crate prefab must have a rigidbody for this to work.
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 TheKnight · Jul 20, 2011 at 02:02 PM

It doesn't show anything still does the same thing. It is shooting it's just shooting up along with the y axis and it's shooting with an akward interval. Shoots one that doesn't go normal and stops and when second is shot it pushes the first.

Comment
Add comment · Show 8 · 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 almo · Jul 20, 2011 at 02:24 PM 0
Share

Add comments as comments, not as answers.

avatar image TheKnight · Jul 20, 2011 at 02:28 PM 0
Share

I cannot seem to add a comment to the replies i get that's why i'm posting as answers

avatar image almo · Jul 20, 2011 at 02:47 PM 0
Share

Just click the "Add New Comment" button.

avatar image TheKnight · Jul 20, 2011 at 03:04 PM 0
Share

To me this only seems to work on my posts not for example on aldonaletto post.

avatar image TheKnight · Jul 21, 2011 at 12:00 AM 2
Share

If it's like that, isn't that a little stupid? Users get downvoted just because they are posting new replies ins$$anonymous$$d of commnents while they can't post.

Show more comments
avatar image
0

Answer by TheKnight · Jul 20, 2011 at 02:21 PM

aldonaletto - That did the trick. But in the tutorial I watched it was Rigidbody and it worked. It's case sensitive? In the editor if I write it as Rigidbody it turns blue, if not it doesn't turn any color.

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 aldonaletto · Jul 20, 2011 at 02:58 PM 0
Share

Yes, Unityscript is case sensitive: Rigidbody is a type, while rigidbody is one of the transform variables. I don't know why the editor didn't turned it to blue - it should, since it's one of the words it "knows" (it's blue in my editor).
NOTE 1: you may notice the crate is always facing the same axis, no matter to what direction it's thrown. Change Quaternion.identity to transform.direction in Instantiate to fix this.
NOTE 2: Unity Answers is different from forums - you must use "Your answer" only to answer to the question; everything else must be posted with the "comment" button in order to not confuse other people (they will think this question have 3 different answers, for instance)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Gun Firing help? 2 Answers

fps shooting in the direction of character main cam 1 Answer

Swich fire button form F to LMB 1 Answer

An instance of type (Script) is required to access non static member (Script) 1 Answer

Checkpoint script? 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