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