How to call SpriteManager in JS?

Hi, guys.
I am going to build a 2d project. There is a awesome code “SpriteManager”.
But I have no idea of C#. So I am tring if I can call SpriteManager in JS. But I got a trouble.

I typed “var DefaultSpriteManager : SpriteManager = null;” at the top of one code.
But Unity alarmed me an error : “The name SpriteManager does not denote a valid type.”
I can call SpriteManager in C# correctly.

So, plz help me if you know what happened here.
Thanks.

create a folder called “Plugins” (in the root of Assets), and put all Sprite Manager files there.

after that you’ll be able to access SM from any script.

@robotive
What a cute guy you are!
It works now.

Another question. What’s “f” meaning in C#?
I got a code like “DefaultSpriteManager.AddSprite((GameObject)test,1f,1f,251,509,256,256,false);”

Thanks.

It means that your number is Float type.

“f” stands for Float in C#, its equivalent with 1.0 in JS.

Yes, it is. Thanks.

One more question: Unity gave me another warning again.

“NullReferenceException : Object reference not set to an instance of an object.”

During the warning, the code was running well.

Here is my code:

var DefaultSpriteManager : SpriteManager = null;
var test : Sprite;
function Start()
{
 test = DefaultSpriteManager.AddSprite(gameObject,1,1,251,509,256,256,false);
}

maybe you need to change it to this:

var DefaultSpriteManager : SpriteManager; 
var test : Sprite; 
function Start() 
{ 
DefaultSpriteManager = new SpriteManager();
 test = DefaultSpriteManager.AddSprite(gameObject,1,1,251,509,256,256,false); 
}

btw, i’m using SM in a little different way.

i created an GameObject, and attached LinkedSpriteManager script to it, and after that i assigned this GameObject to a var in other file, through Editor.

NO, not yet.
Unity alarm in different way. Maybe you can’t use new keyword for monobehavior.
I found why I got the warning, I forgot there were 2 objects, and I didnt drag “SpriteManager” to another in editor. It’s a big lapsus. Sorry.

robotive. Thank you. And thank all guys who replied me.

no problems :slight_smile:

Yes, you have to add the SpriteManager script to a GO, then create a reference to it in your script, and drag the GO onto that reference in the editor to establish the link.

Also, be sure to call RemoveSprite() before you ever call Destroy() on an associated GameObject. So if you have a sprite that represents a car, always call RemoveSprite() on the car’s sprite object first before you call Destroy on the car’s GameObject. Otherwise, you’ll get an exception.