Hi all,
I have following code. I am trying to get clicked sprite name at run time. I have added rigidbody2d and boxcolider2d but I am not getting name… Attached image
public class test : MonoBehaviour {
public Sprite[] card;
public List <Sprite> items;
public Transform start;
public float howManyAdded; // How many cards I added so far
float gapFromOneItemToTheNextOne; //the gap I need between each card
void Awake()
{
// load all frames in cards array
card = Resources.LoadAll<Sprite>("CardDeck_");
}
void Start()
{
howManyAdded = 0.0f;
gapFromOneItemToTheNextOne = 0.2f;
GameObject cards = new GameObject();
GameObject cardPart1 = new GameObject();
//cardPart1.SetParent(cards.transform);
cardPart1.transform.position = start.position;
cardPart1.transform.position += new Vector3 (( howManyAdded*gapFromOneItemToTheNextOne), 0, 0);
cardPart1.transform.Rotate( 0f, 0f, -6f );
cardPart1.transform.SetParent(cards.transform);
howManyAdded++;
cardPart1.AddComponent<SpriteRenderer>();
cardPart1.GetComponent<SpriteRenderer>().sprite = card[8];
GameObject cardPart2 = new GameObject();
//cardPart2.SetParent(cards.transform);
//cardPart2.transform.SetParent ();
cardPart2.transform.position = start.position;
cardPart2.transform.position += new Vector3 (( howManyAdded*gapFromOneItemToTheNextOne), 0, 0);
cardPart2.transform.Rotate( 0f, 0f, -6f );
cardPart2.transform.SetParent(cards.transform);
//Rigidbody2D gameObjectsRigidBody = cardPart2.AddComponent<Rigidbody2D>();
//gameObjectsRigidBody.
//gameObjectsRigidBody.isKinematic = true;
cardPart2.AddComponent<SpriteRenderer>();
cardPart2.GetComponent<SpriteRenderer>().sprite = card[15];
}
void OnMouseDown(){
Debug.Log("Sprite Clicked");
}
}