• 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 Dylanpolis · Aug 01, 2017 at 11:32 PM · javascriptscripting problemscripting beginnerscript error

Dont know what im doing wrong?(Error included) (Javascipt)

Error:Assets/die.js(8,30): BCE0005: Unknown identifier: 'Chase'.

  #pragma strict
 
 function Update () {
  }
  
  function OnTriggerEnter (col : Collider) {
      if(col.gameObject.tag == "Weapon") {
      GetComponent(Chase).enabled = false;
          GetComponent.<Animation>().Play();
  
      }
  }
Comment
Add comment · Show 6
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 UnityCoach · Aug 01, 2017 at 11:42 PM 0
Share

You're mixing JS and C#. I just replied to your other question, in full.

avatar image Bunny83 UnityCoach · Aug 02, 2017 at 01:20 AM 1
Share

He doesn't really mix UnityScript and C# here. This is all valid UnityScript. However the error clearly said that there is nothing with the name "Chase". So he most likely has a typo (maybe different casing) or he doesn't know what he actually want or what he's doing.

Show more comments
avatar image toddisarockstar · Aug 03, 2017 at 06:20 AM 0
Share

get component the way he stated it requires a string input ... he simply missed the quotes. it should be:

  GetComponent("Chase").enabled = false;

or this would work too if you don't need a string lookup.

  GetComponent.<Chase>().enabled=false;









i havent written unity script in awhile so i might be wrong but doesn't unity script need var infront of freshly declaired variables ???

 function OnTriggerEnter (var col : Collider) {

 
avatar image Bunny83 toddisarockstar · Aug 04, 2017 at 09:31 AM 0
Share

No, that's wrong. The code is perfectly fine. This line in UnityScript:

 GetComponent(Chase);

Is equal to this in C#

 ((Chase)GetComponent(typeof(Chase)))

So the first example is how you should do it in UnityScript.

The error simply states that there is no class with the name Chase within the current set of namespaces. So neither in the global namespace nor in the currently imported namespaces is any class with the name "Chase".

So he either misspelled the actual class / script name (Note: case sensitive!) or he's missing that class somehow.

Also even if the class existed, this wouldn't work with pragma strict:

 GetComponent("Chase").enabled = false

Because the string version returns the base type "Component". Components do not have an enabled property. When using pragma strict everything is strongly typed. Your line would only work with dynamic typing support (i.e. no pragma strict). However that is much slower and isn't recommended

ps: No, "var" is only needed when you declare member variables or local variables inside methods. Arguments are always local variables. It wouldn't make much sense to require the "var" keyword here.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Error while creating an object 0 Answers

(C# and Java)Unable to give the Damage from enemy bullet script to Player Health. 3 Answers

How to share varibles betweent scripts 4 Answers

3rd Person Camera to Rotate With the Player 0 Answers

Rocket Projectiles in Flight Simulator error 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