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.
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);
}
var DefaultSpriteManager : SpriteManager;
var test : Sprite;
function Start()
{
DefaultSpriteManager = new SpriteManager();
test = DefaultSpriteManager.AddSprite(gameObject,1,1,251,509,256,256,false);
}
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.
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.