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 dfghdh · Mar 25, 2013 at 05:44 PM · c#javascriptcompiling

Calling c# function from a JS

Hi I have a script (written in c#) that I need to use from my unity script system. I have looked around at how to invoke a function inside the c# script but cannot find anything that helps me.

Before you ask, the c# files are located in the standard assets and get compiled before the java script files.

The error I get when trying to invoke the function is as follows: "It's not possible to invoke an expression of type 'error'. (BCE0077)

The c# function has a void return type. See the complete code below.

 //GameMaster.js
 enum GameMode{MENU, PLAYING};
 var playerSpawn : GameObject;
 var playerPrefab : GameObject;
 var player : Player;
 var toggleType : String;
 var gameTimeElapsed : double;
 var maxGameTime : double;
 var gameMode : GameMode;
 var stringToEdit : String;
 var gameFont : GameFont; //c# script
 var enemies = Array();
 
 function Awake()
 {
     gameFont = gameObject.GetComponent(GameFont); //get the c#script
 }
 function Start()
 {
     gameFont.AddText("Hello", 32, 40); //error see post
     //SetupMenu();
     //SetupGame();
 }
 
 //GameFont.cs
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class GameFont : MonoBehaviour 
 {
     public TextAsset fontXML;
 
     public SpriteManager spriteManager;
     BitmapFont bmf;
     
     void Start () 
     {
         spriteManager = GameObject.Find("SpriteManager").GetComponent<SpriteManager>();
         bmf = new BitmapFont(fontXML.text, 0, 0);
     }
     
     void AddText(string text, int x, int y)
     {
         AddText(bmf, text, x, y);    
     }
     void AddText(BitmapFont bmf, string text, int x, int y)
     {
         List<BitmapFont.Sprite> sprites = bmf.GetSprites(text, 0, 0);
         
         foreach(BitmapFont.Sprite s in sprites)
         {
             GameObject go = new GameObject("Glyph \"" + s.c + "\"");
             go.transform.position = new Vector3(s.x + x + s.texCoords.width/2, Screen.height - y - s.y + s.texCoords.height/2, 0.0f);
             
             spriteManager.AddSprite(go, s.texCoords.width, s.texCoords.height, (int)s.texCoords.x, (int)s.texCoords.y + (int)s.texCoords.height, (int)s.texCoords.width, (int)s.texCoords.height, false);
         }
     }    
 }

I am using the package created by this guy: http://forum.unity3d.com/threads/87782-Pixel-Perfect-Bitmap-Font-in-Unity

Comment
Add comment · Show 4
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 whydoidoit · Mar 25, 2013 at 05:59 PM 0
Share

gameFont is != null in Awake? The JS isn't in PlugIns or Standard Assets? Oh and compile or run time error?

avatar image dfghdh · Mar 25, 2013 at 06:01 PM 0
Share

gameFont is not null, the JS's are in "$$anonymous$$yAssets/Scripts" the c# scripts are in "StandardAssets/Scripts"

Edit: Compile Time error - Scripts won't compile - oh and its the only error so not caused by another error

avatar image Bluestrike · Mar 26, 2013 at 07:46 AM 0
Share

Since you mention having the scripts in the standard assets folder, did you mean the plugin folder? I once had a support reply telling me to place cs scripts there to have them compiled first.

avatar image dfghdh · Mar 26, 2013 at 08:12 AM 0
Share

As far as i'm aware both StandardAssests and the Plugin folder are compiled before user created folders such as $$anonymous$$yAssets

But no I did mean the StandardAssestFolder

1 Reply

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

Answer by whydoidoit · Mar 25, 2013 at 06:05 PM

That AddText call doesn't appear to be public...

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 dfghdh · Mar 25, 2013 at 06:08 PM 0
Share

Thanks, silly to miss that :)

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

12 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Play music trough scenes 0 Answers

Fonts not displaying properly when loaded through script 0 Answers

I can do this in JS or not ??? 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