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 /
  • Help Room /
avatar image
0
Question by yvyv1000 · Oct 20, 2015 at 03:55 PM · getcomponentscript error

GetComponent

i have a problem with unity and i thing the new unity API is shit because of it

  var projectile : Transform;
  var speed = 1;
  var barrel : Transform;
  var shots :  int  =  0 ;
  var maxShots :  int  =  1 ;
  
  function Update () {
  
  if ( Input.GetButtonDown ("Fire1") && shots < maxShots){
  
  clone = Instantiate(projectile, barrel.position, barrel.rotation);
  
 clone.GetComponent<Rigidbody>().velocity = barrel.TransformDirection(Vector3 (0, 0, speed)); 
  shots ++;
  
  }
  else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
      {
  yield WaitForSeconds(0.5); 
          shots = 0;
      }
  }

maybe im wrong but that script is fine, i did exactly what the scripting reference said but i always get these errors:

Assets/MY Assets/Scripts/StoneFire.js(13,31): BCE0043: Unexpected token: ).

Assets/MY Assets/Scripts/StoneFire.js(13,32): BCE0044: expecting ), found '.'.

Assets/MY Assets/Scripts/StoneFire.js(13,33): UCE0001: ';' expected. Insert a semicolon at the end.

can someone please tell me what im doing wrong because i dont get. every time i change the things to what the errors say there will just appear errors about the fixed errors saying i should go back to the old thing (script showed above).

thanks i wou,d really appriciate your help

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 allenallenallen · Oct 20, 2015 at 04:00 PM

Unity's new API is shit? lol? Do you even know what you're saying?

The error is saying that something is wrong with this line right here:

 clone.GetComponent().velocity = barrel.TransformDirection(Vector3 (0, 0, speed)); 

Look at the API: http://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html

Remember to click JS on the top right corner in the API pages, not C# because that's the mistake you made.

Use

 clone.GetComponent(Rigidbody)

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 yvyv1000 · Oct 20, 2015 at 06:51 PM 0
Share

sorry i was just a little mad thanks for your answer it worked but your line does not has but you probably meant that

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

32 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

Related Questions

Enemy AI Script Error 1 Answer

How can i change bool of other gameobject? 1 Answer

Changing animation using GetComponent 0 Answers

how do I add link script to gameobject that already exist with attached script 1 Answer

Script does not recognise gameObjects 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