how to use OnMouseDown() instead of if(Input.GetKeyDown(“s”))?
here is my code…
using UnityEngine;
using System.Collections;
public class shuffle : MonoBehaviour {
float pos1_x=-3.5f;
float pos1_y=-3.5f;
float pos2_x=6.0f;
float pos2_y=2.5f;
float pos3_x=-3.5f;
float pos3_y=3.5f;
float pos4_x=-6.0f;
float pos4_y=2.5f;
int[] cardno=new int[32];
void Update (){
Transform[] allChildren= gameObject.GetComponentsInChildren<Transform>();
int i=-1;
int j;
foreach(Transform child in allChildren) {
if(child.gameObject.name.Length<4)
{
i++;
cardno[i]= child.gameObject.GetComponent<SpriteRenderer>().sortingOrder;
}
}
if(Input.GetKeyDown("s")){
for(int m=0;m<9;m++){
card_Shuffle(cardno);
i=-1;
foreach(Transform child in allChildren) {
if(child.gameObject.name.Length<4)
{
i++;
child.gameObject.GetComponent<SpriteRenderer>().sortingOrder=cardno[i];
}
}
}
i=-1;
j=0;
foreach(Transform child in allChildren) {
if(child.gameObject.name.Length<4)
{
i++;
child.gameObject.GetComponent<SpriteRenderer>().sortingOrder=cardno[i];
if(cardno[i]>=0 cardno[i]<4){
child.gameObject.transform.position=new Vector3(pos1_x+1f*j,pos1_y,0);
child.gameObject.GetComponent<SpriteRenderer>().sortingOrder=j;
j++;
}
else if(cardno[i]>=4 cardno[i]<8) child.gameObject.transform.position=new Vector3(pos2_x,pos2_y-.75f*(cardno[i]-4),0);
else if(cardno[i]>=8 cardno[i]<12) child.gameObject.transform.position=new Vector3(pos3_x+1f*(cardno[i]-8),pos3_y,0);
else if(cardno[i]>=12 cardno[i]<16) child.gameObject.transform.position=new Vector3(pos4_x,pos4_y-.75f*(cardno[i]-12),0);
}
}
}
}