Sprite Manager interfacing with UnityScript code?

Anyone know how to do this? I have done C# previously, but since I started with Unity I wanted to “Embrace the culture”, and as Unity’s documentation is all UnityScript based, I’ve done NO development in C# in Unity.

I wanna use SpriteManager now, though, and that needs it! :?

Any suggestions?

I’m facing the same problem too. Has anybody managed to fully handle SpriteManager methods from within JavaScript code?

There are some very simple examples in SM topic (around page 12) but if someone has a more thorough client jscript it would be of great help!

Thanks :slight_smile:

yeah, if you read through that thread people discuss that. One guy had his whole project set up in javascript and had that same issue initially. I guess you just need to make a folder in the root of your assets folder and call it “Plugins”. – then you put the two C# scripts in there.

You should be able to reference the SpriteManager class after that.

*** Yesterday, I posted the following message in SpriteManager thread but it has already been barried without an answer. I am reposting it here with a hope that someone will give a solution.

(Today is the last day of my unity trial period, and I am struggling to verify that SM could be a viable solution for iphone 2d development. Thanks for any help!)


I am trying to extend the JavaScript example given in the middle of page 12 of SpriteManager topic http://forum.unity3d.com/viewtopic.php?t=17864&postdays=0&postorder=asc&start=165

It works ok, but when adding a rigidbody (with gravity) to the client the linked sprite doesn’t follow the object as it falls downwards. Same applies when adding a physics force.

Has anybody managed to properly implement the SM from within JavaScript? What do I miss? Rolling Eyes

Here is my client script:

var sprHolder:GameObject;
var sprManager:SpriteManager;
var spr : Sprite;

function Awake () {
   sprHolder =  GameObject.Find("SpritesHolder");
   sprManager = sprHolder.GetComponent("SpriteManager");
}

function Start() {
   var spr = sprManager.AddSprite(gameObject, .5, .5, 3, 120, 128, 128, true);
}

function Update () {
rigidbody.AddRelativeForce(0.1, 0, 0);

And here is the whole package…

151146–5505–$sm_js_128.unitypackage (229 KB)

I think the answer might be really easy. You need to use LinkedSpriteManager instead of plain old SpriteManager. So just change the script that the SpriteManager object in your scene is using.

Regular SpriteManager doesn’t automatically update the position of sprites objects when their parent moves, you’re supposed to do it manually. LinkedSpriteManager does autoupdate positions.

I’ll grab your project to make sure, but your code looks right.

edit: Yep that did it. LinkedSpriteManager is the key.

Yes, it works now :slight_smile:
Many thanks!

I am now trying to destroy an object from withing its script. I have put the following code inside Update():

if (transform.position.x>6) {
	sprManager.RemoveSprite(spr);
	Destroy(gameObject);	
}

…where “spr” is the sprite variable that was used to receive output from AddSprite().

When running the project i get the error:

NullReferenceException: Object reference not set to an instance of an object
SpriteManager.RemoveSprite (.Sprite sprite)

Any ideas of what is going on? :?

function Start() { 
   var spr = sprManager.AddSprite(gameObject, .5, .5, 3, 120, 128, 128, true); 
}

In your start function you are using “var spr =” when it should be “spr =”. What you’re doing there is creating a local variable that disappears as soon as the Start() function ends, instead of using the global variable you intended.

Can anyone see anything wrong with the following script?

I’m getting the following error:
NullReferenceException: Object reference not set to an instance of an object
Sprite.Transform () (at Assets/plugins/Sprite.cs:214)

The problem seems to be in the following line. If I change ball1 to ballPrefab like so… then the sprite is created properly except that it’s created at 0,0,0 rather than at the Instantiated position.

	sprite1 = _mySpriteManager.AddSprite(ballPrefab, .5, .5, 3, 120, 128, 128, true);

Here’s the whole script with the error:

var _spriteManagerReference:GameObject;
var _mySpriteManager:SpriteManager;
var ballPrefab : GameObject;
var sprite1;
var ball1;

function Awake () {
	_spriteManagerReference =  gameObject.Find("SpriteManagerGO");
	_mySpriteManager = _spriteManagerReference.GetComponent("SpriteManager");
}

function Start() {
	CreateSprites();
	CreateGameObjects();
}

function CreateGameObjects() {
	ball1 = Instantiate(ballPrefab, Vector3 (6, 0.2, 0), Quaternion.identity); 
}

function CreateSprites() {
	sprite1 = _mySpriteManager.AddSprite(ball1, .5, .5, 3, 120, 128, 128, true);
}

meanstreak, I know I’m resurrecting a really old thread here, and you’ve probably got it figured out already, but just incase, check to make sure the object to which the SpriteManager script is a component is at 0,0,0. It is what holds the mesh. Otherwise, all your sprites will be offset.

Hey all,
I’m new to Unity and programming in general, and have recently been just tootling around making a 2D Tower Defense style game in Unity. I’m trying to use SpriteManager to deal with my draw calls (the game is sorta-kinda for iphone), and am having a bit of trouble interfacing with javascript. Im much more comfortable with JS/US than C# as the tutorials I’m following are all JS centered. I was just wondering if one of y’all could //comment in what exactly the scripts above are doing, as im having a bit of trouble telling what gameobjects I need to create and how they should be referenced/tie together. Again, I’m really new to all this, so any help actually getting a sprite to actually render with SpriteManager at all is welcome.