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 PiMuRho · Feb 03, 2012 at 06:08 PM · getcomponent

An issue with GetComponent

I'm in the process of neatening up my scripts to package it all together into one prefab, which basically consists of a main controller, a rocket launch system and some turrets. So far, I'm working on getting the main controller to find a target and then assign it to the other components. Turrets work, the missile launcher will trigger based on the correct target.

However, the missiles are a different matter. They're prefabs instantiated from a series of spawn points, and use their own targeting system. I'm attempting instead to pass the target to them from the controller.

In the script for my launcher, I have this:

 var missileProjectile : Rigidbody = Instantiate( 
    projectile, slot.position, slot.rotation ); //create clone of projectile at the right position/orientation
 
   missileProjectile.velocity =
    transform.TransformDirection( Vector3.forward * speed ); //give it some speed

and then I attempt to pass it the target:

 missileProjectile.GetComponent(missileHomingScript).missiletarget  = LookAtTarget ;

Where missileHomingScript is the script attached to the prefab, and LookAtTarget is the name of the target.

Unity throws me this error: Assets/Standard Assets/Scripts/Component Scripts/Weapon Component/multi_missile_launcher_script.js(88,40): BCE0005: Unknown identifier: 'missileHomingScript'.

I've scoured every resource I can find, and I'm pretty certain that the syntax is correct. So why am I getting this error?

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

2 Replies

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

Answer by Bunny83 · Feb 03, 2012 at 07:06 PM

I guess "missileHomingScript" is outside of the "Standard Assets" folder. Scripts in "Standard Assets" are compiled before all "normal" scripts like you can read in Eric's link. You should either move your "multi_missile_launcher_script" out of "Standard Assets" or put your "missileHomingScript" also in Standard Assets.

I would strongly recommend to move them out of this folder. This folder should only be used for complete script packages that don't belong on other things. That way they are available to all languages.

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 PiMuRho · Feb 03, 2012 at 07:32 PM 0
Share

That did it! Thanks a lot! I knew it would be something simple. Looks like I'd better get busy reorganising my assets.

avatar image
1

Answer by Eric5h5 · Feb 03, 2012 at 06:23 PM

There's nothing called "missileHomingScript" that is available to the script when being compiled. Either that's a typo (the convention is to use capital letters for classes, so I would have called it MissileHomingScript instead), or else it's a C# script that's not visible to the JS script (see here).

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 PiMuRho · Feb 03, 2012 at 06:56 PM 0
Share

Thanks for the response! missileHo$$anonymous$$gScript is the script attached to the missile, the one that I'm trying to pass the target variable to. It's definitely not a C# script! I've got a similar system to work with other prefabs, so I think my best course of action at this point is to do some rewriting and see how it comes out.

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Why do I have to call ToString() when fetching a String from another script? 2 Answers

enemy attack not recognizing players stats 1 Answer

How to get a variable value from another script(C#)? 1 Answer

Cannot seem to get a reference to a script component to work, despite many different attempts and a lot of work 2 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