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 mido555 · Jul 06, 2011 at 10:37 AM · errorinstantiategetcomponentcollidebce0018

disabling a script when collide with a cube

Hi, i want to make an enemy behind a corner come out and follow you when you step on a cube. I have all the scripts but this one doesn't work i dont know why here's my script:

 function OnControllerColliderHit(hit:ControllerColliderHit) {
 
 var script : EnemyAI;
 
 var script : EnemyAttack;
 
 
 if(hit.gameObject.tag == "Instantiate enemy")
 
     {
             GetComponent(EnemyAI).enabled = true;
             GetComponent(EnemyAttack).enabled = true;
     }
 
 }

what should i do? the enemy has EnemyAI and EnemyAttack disabled and when you step on a cube i want them to be enabled but i get 2 errors:

Assets/Scripts/Enable script.js(4,14): BCE0018: The name 'EnemyAI' does not denote a valid type ('not found'). Did you mean 'System.Enum'?

Assets/Scripts/Enable script.js(5,14): BCE0018: The name 'EnemyAttack' does not denote a valid type ('not found').

Comment
Add comment · Show 7
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 GuyTidhar · Jul 06, 2011 at 12:01 PM 0
Share

Do you have a script named "EnemyAI" and a script named "EnemyAttack"?

If you do - is it in Javascript? C#?

Where is it located and where is the script you have shown us your code from is located?

avatar image almo · Jul 06, 2011 at 12:55 PM 0
Share

format your code with the 010101 button

avatar image hursty90 · Jul 06, 2011 at 01:33 PM 0
Share

just a check, but this script isn't running from the disabled script?

avatar image mido555 · Jul 07, 2011 at 01:57 PM 0
Share

Yes i do but there both in c#

avatar image mido555 · Jul 07, 2011 at 01:58 PM 0
Share

there both in the same folder named Scripts

Show more comments

3 Replies

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

Answer by kieblera5 · Jul 07, 2011 at 04:48 PM

Please cache the components...

 var enemyAIScript : EnemyAI;
 var enemyAttackScript : EnemyAttack;
 
 function Start()
 {
      enemyAIScript=gameObject.GetComponent.<EnemyAI>();
      enemyAttackScript=gameObject.GetComponent.<EnemyAttack>();
 }
 function OnControllerColliderHit(hit:ControllerColliderHit) 
 {
 if(hit.gameObject.tag == "Instantiate enemy")
 
     {
             enemyAIScript.enabled = true;
             enemyAttackScript.enabled = true;
     }
 
 }

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 kieblera5 · Jul 07, 2011 at 04:50 PM 0
Share

Also note that the these scripts must be attached to the object that this script is attached to. If not, you will first have to cache the enemy object, find it, and then get the component from that object

avatar image
1

Answer by GuyTidhar · Jul 07, 2011 at 05:08 PM

Leave this script where it is and move your two C# scripts (EnemyAI, EnemyAttack) under a folder named: "Plugins" - create one if it does not exist yet).

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 kieblera5 · Jul 07, 2011 at 05:11 PM 0
Share

This should work. I didn't know that they were C# scripts. Either way, take note of what I said and cache your components, so that you don't end up using GetComponent multiple times.

avatar image mido555 · Jul 07, 2011 at 05:13 PM 0
Share

And this script you wrote must be attached to my enemy or something else?

avatar image dibonaj · Jul 07, 2011 at 05:20 PM 0
Share

Also note, always move things around inside of the Project View inside of Unity. Never move them around in the folders on your computer.

avatar image kieblera5 · Jul 07, 2011 at 05:20 PM 0
Share

The way I wrote my script, I assumed all the scripts were attached to the same GO. If not you will have to find the GO and pull it's component ins$$anonymous$$d of the current GO.

avatar image
1

Answer by dibonaj · Jul 07, 2011 at 05:16 PM

Take a look at this: http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html

Unity compiles scripts in a certain order. So if you are ever trying to access C# from JavaScript or the other way around, you need to make sure you have them in the proper location. Either move your C# script to a folder called Plugins or move your JavaScript files to the Standard Assets folder.

Comment
Add comment · Show 7 · 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 dibonaj · Jul 07, 2011 at 05:16 PM 0
Share

Aww, someone beat me to it :P

avatar image mido555 · Jul 07, 2011 at 05:22 PM 0
Share

Thank you soooooooooo much it worked you are the definition of awesome sauce. I just have one more question, i have to add the enemy to the script in the inspector but i have to do it in run time, how can i make it work right when i click the play button and not have to add all the stuff in the incpector?

avatar image mido555 · Jul 07, 2011 at 05:25 PM 0
Share

I just noticed that i get an error that can be erased NullReferenceException: Object reference not set to an instance of an object Enable script.OnControllerColliderHit (UnityEngine.ControllerColliderHit hit) (at Assets/Scripts/Enable script.js:14) UnityEngine.CharacterController:$$anonymous$$ove(Vector3) Character$$anonymous$$otor:UpdateFunction() (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Character$$anonymous$$otor.js:229) Character$$anonymous$$otor:FixedUpdate() (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Character$$anonymous$$otor.js:331)

what does it mean?

avatar image dibonaj · Jul 07, 2011 at 05:30 PM 0
Share

For your first question, you should probably start up a new thread and ask that question. Also, if you can select multiple answers as the correct answer, then select $$anonymous$$e and GuyT since they basically say the same thing. If not, select his since he said it first.

Now, can you update your original post at the top with the script that the error takes you to? I need to know which line it is.

avatar image mido555 · Jul 07, 2011 at 05:32 PM 0
Share

The error suddenly disappeared...lol

Show more comments

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

Instantiate Prefabs. Errors. 2 Answers

The type or namespace name `RigidbodyFirstPersonController' could not be found? 1 Answer

GameObject.getComponent problem 2 Answers

Photon instantiate (Assign Instantiated . get component 1 Answer

"Destroy assets is not permitted to avoid data loss" 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