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 awesomedata · May 11, 2015 at 03:50 PM · classesmethods

How do I use JS to access C# methods/classes?

I have 2 scripts -- a C# script that does some math, and one JS/UnityScript that should utilize its methods. Only the UnityScript is attached to a game object.

For some reason, no matter how I set up the scripts or variables, I keep getting the "Unknown identifier: OSM" BCE0005 error. I've even went so far as to put the C# script into a Plugins folder so it will compile earlier, but for some reason, the JS still can't see the OSM class and its methods!

Here's my code (Note, the Update function is omitted for brevity):

Javascript :

 function MapPosition() {
   var tx : Vector2;
   tx = OSM.WorldToTile(fixLon,fixLat);
   }


C# :

 using UnityEngine;
 using System.Collections;
 using System;
 
 
 public class OSM {
 
     public Vector2 WorldToTile(double lon, double lat, int zoom)
     {
         Vector2 p = new Vector2();
         p.x = (float)((lon + 180.0) / 360.0 * (1 << zoom));
         p.y = (float)((1.0 - Math.Log(Math.Tan(lat * Math.PI / 180.0) + 
                                       1.0 / Math.Cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << zoom));
         
         return p;
     }
     
     public Vector2 TileToWorld(double tile_x, double tile_y, int zoom) 
     {
         Vector2 p = new Vector2();
         double n = Math.PI - ((2.0 * Math.PI * tile_y) / Math.Pow(2.0, zoom));
         
         p.x = (float)((tile_x / Math.Pow(2.0, zoom) * 360.0) - 180.0);
         p.y = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n)));
         
         return p;
     }
 }
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
0
Best Answer

Answer by awesomedata · Dec 18, 2016 at 12:15 AM

It required being put into a new project for some reason. After that, it worked fine. I'm assuming it was a fluke with my asset database or something. :/

Sooo strange... :(

Comment
Add comment · 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
0

Answer by NorthernVisionStudio · May 11, 2015 at 04:01 PM

You are trying to use the OSM class without an object instantiation. Please try

1) new OSM object before calling methods

OR

2) make the methods static so that you don't need an object instance to access them.

Comment
Add comment · Show 3 · 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 awesomedata · May 11, 2015 at 04:29 PM 0
Share

I've tried your first advice (since I want to eventually use coroutines) :

 var osm = new OS$$anonymous$$();
 var tx : Vector2;
 tx = osm.WorldToTile(fixLon,fixLat);

...but I still receive the "unknown identifier" error.

How do I do the "new OS$$anonymous$$ object" thing you mentioned? I thought that what I did there was the proper way to instantiate a new class 'object' to call its methods?

$$anonymous$$ind giving a code example on how to do either of these???

avatar image awesomedata · May 11, 2015 at 07:20 PM 0
Share

Apparently even making it static doesn't help... I can't find help for this anywhere on the net. Any ideas? Anyone...?

avatar image NorthernVisionStudio · May 17, 2015 at 02:34 PM 0
Share

I just copied and pasted your code into a new project. The JS file was in Assets and the CS file was in Plugins folder. I added 'static' to each method.

No problems on my end.

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

20 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

Related Questions

Can I increment a static variable from a static method? 1 Answer

How can you list all classes inside a namespace (such as UnityEngine) and every message method that class has? 1 Answer

Class Reference to Other Class does not allow me to use its Methods 1 Answer

Learning Unity Methods 1 Answer

Running a method from a subclass? 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