Hello Guest

Author Topic: How can I compare actual sprites?  (Read 4052 times)

Sasuga

  • Newbie
  • *
  • Posts: 1
    • View Profile
How can I compare actual sprites?
« on: October 17, 2013, 05:45:51 am »
Code: [Select]
using UnityEngine;
using System.Collections;

public class TestSprites : MonoBehaviour {
public tk2dSprite thisSprite;
public string spriteName;
public string objectName;

void Awake(){
thisSprite = gameObject.GetComponent<tk2dSprite>();
}

// Use this for initialization
void Start () {
//Sprite image name: mySprite
//Game object's name: myObject
thisSprite.SetSprite(1);
spriteName = thisSprite.name;
objectName = gameObject.name;
if(spriteName == objectName)
Debug.Log ("They're the same!");
else
Debug.Log ("They're not the same!");
}

When I run the above code my Console says:
Code: [Select]
They're the same!
UnityEngine.Debug:Log(Object)
TestSprites:Start() (at Assets/TestSprites.cs:21)

I don't see any place in the scripting reference to get the name of the sprite/image out as a string for tk2dSprite and I've tried searching the web.  If it exists can someone point me to it?  If it doesn't, can it please get added?

I'd like to be able to allow people to scroll through a list of sprites and display their names below them.
I'd like to be able to check if a sprite's name matches against a string for things like bug checking.

I'm sure being able to get the name out is useful for other things as well.

I'd like to be able to put the SpriteID in and get the Sprite's name out.
In case there's confusion, the string I'm looking for is the one that appears in the drop-down-menu next to "Sprite" which is under "Collection" in the "Tk 2d Sprite (Script)" component.

Thanks,
Sasuga
« Last Edit: October 17, 2013, 05:49:09 am by Sasuga »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I compare actual sprites?
« Reply #1 on: October 17, 2013, 01:09:50 pm »
thisSprite.CurrentSprite.name gives you the name
thisSprite.spriteId gives you the Id.

thisSprite is a component, all components have the same .name as the gameobject its hosted on, which is why you're finding it the same.