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 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.

avatar image UnityCoach Bunny83 · Aug 02, 2017 at 08:02 AM 0
Share

I believe the point after GetComponent doesn't work. $$anonymous$$y JavaScript isn't what it was, but I believed the typed version of GetComponent was C# only.

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.

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

Trying to setbool of animator from another object c# 1 Answer

How do I make my projectile deal damage to a target it hit. 1 Answer

Activate/Deactivate Scripts form another Script 2 Answers

"Only assignment, call, increment, decrement and new object expressions can be used as statements" 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