var countDownObj:GameObject;
var gameStatus:int; // 0 wait 1:play
var clickStartObject:GameObject;
var removeObjectList:Array;
var lineObject:GameObject;
if(Input.GetMouseButtonDown(0)){
if(clickStartObject == null){
removeObjectList = new Array();
var hit:RaycastHit2D =Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hit.collider != null) {
if(hit.collider.gameObject.name.IndexOf("Drop") != -1){
clickStartObject = hit.collider.gameObject;
removeObjectList.push(clickStartObject);
var dropTexture:tk2dSprite = clickStartObject.GetComponent(tk2dSprite);
dropTexture.color.a = 0.5;
hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hit.collider != null) {
if(hit.collider.gameObject.name == clickStartObject.name){
for(var i:int = 0; i < removeObjectList.length; i++){
var obj:GameObject = removeObjectList[i];
if(obj == hit.collider.gameObject){
dropTexture = hit.collider.gameObject.GetComponent(tk2dSprite);
dropTexture.color.a = 0.5;
removeObjectList.push(hit.collider.gameObject);
for(i = idExistNo + 1; i < removeObjectList.length; i++){
obj = removeObjectList[i];
obj.GetComponent(tk2dSprite).color.a = 1;
removeObjectList.splice(idExistNo + 1, removeObjectList.length - idExistNo - 1);
var dropObject:Drop2Object = clickStartObject.GetComponent(Drop2Object);
if(removeObjectList.length == dropObject.count){
for(i = 0; i < removeObjectList.length; i++){
obj = removeObjectList[i];
var removeObj:Drop2Object = obj.GetComponent(Drop2Object);
dropList[removeObj.posX + removeObj.posY * DROP_COL] = null;
for(i = 0; i < removeObjectList.length; i++){
obj = removeObjectList[i];
dropTexture = obj.GetComponent(tk2dSprite);
dropTexture.color.a = 1.0;
removeObjectList = new Array();
for(var x:int = 0; x < DROP_COL; x++){
var maxCount:int = 0; //画面外の何個目か
for(var y:int = DROP_ROW - 1; y >= 0; y--){
if(dropList[x + y * DROP_COL] == null){
var drop:GameObject = createDrop(x,y);
var posX:float = drop.transform.position.x;
drop.transform.position.x = -1.0 * maxCount;
iTween.MoveTo(drop, iTween.Hash("x", posX, "delay", 0, "time", 0.3, "easeType", "easeInOutQuad"));
dropList[x + y * DROP_COL] = drop;
function GetDrop(posX:int, posY:int){
return dropList[posX + posY * DROP_COL];
redCount = Random.Range(2,5);
greenCount = Random.Range(2,5);
blueCount = Random.Range(2,5);
yellowCount = Random.Range(2,5);
countDownObj.SetActive(false);
for(var y:int = 0; y < DROP_ROW; y++){
for(var x:int = 0; x < DROP_COL; x++){
var drop:GameObject = createDrop(x,y);
private function createDrop(x:int, y:int){
var drop:GameObject = Instantiate(Resources.Load("Prefabs/Drop2"));
drop.transform.position.x = x * 1.0;
var posY:float = -y * 1.0;
if(x % 2 == 0) posY -= 0.5;
drop.transform.position.y = posY;
var dropTexture:tk2dSprite = drop.GetComponent(tk2dSprite);
var spriteId:int = Random.Range(6,10);
dropTexture.spriteId = spriteId;
drop.name = "Drop" + spriteId;
var dropObject:Drop2Object = drop.GetComponent(Drop2Object);
drop.transform.FindChild("Count").GetComponent(tk2dTextMesh).text = count + "";
dropObject.count = count;
private function countDown(){
var countDownText:tk2dTextMesh = countDownObj.GetComponent(tk2dTextMesh);
countDownObj.SetActive(true);
countDownText.text = 3 + "";
iTween.ScaleTo(countDownObj, iTween.Hash("x", 1.2,"y", 1.2, "delay", 0, "time", 0.3, "easeType", "easeInOutQuad"));
iTween.ScaleTo(countDownObj, iTween.Hash("x", 0.8,"y", 0.8, "delay", 0.3, "time", 0.3, "easeType", "easeInOutQuad"));
iTween.ScaleTo(countDownObj, iTween.Hash("x", 1.0,"y", 1.0, "delay", 0.3, "time", 0.3, "easeType", "easeInOutQuad"));
countDownText.text = 2 + "";
iTween.ScaleTo(countDownObj, iTween.Hash("x", 1.2,"y", 1.2, "delay", 0, "time", 0.3, "easeType", "easeInOutQuad"));
iTween.ScaleTo(countDownObj, iTween.Hash("x", 0.8,"y", 0.8, "delay", 0.3, "time", 0.3, "easeType", "easeInOutQuad"));
iTween.ScaleTo(countDownObj, iTween.Hash("x", 1.0,"y", 1.0, "delay", 0.3, "time", 0.3, "easeType", "easeInOutQuad"));
countDownText.text = 1 + "";
iTween.ScaleTo(countDownObj, iTween.Hash("x", 1.2,"y", 1.2, "delay", 0, "time", 0.3, "easeType", "easeInOutQuad"));
iTween.ScaleTo(countDownObj, iTween.Hash("x", 0.8,"y", 0.8, "delay", 0.3, "time", 0.3, "easeType", "easeInOutQuad"));
iTween.ScaleTo(countDownObj, iTween.Hash("x", 1.0,"y", 1.0, "delay", 0.3, "time", 0.3, "easeType", "easeInOutQuad"));
countDownText.text = "Start";
iTween.ScaleTo(countDownObj, iTween.Hash("x", 1.4,"y", 1.4, "delay", 0, "time", 0.5, "easeType", "easeInOutQuad"));
iTween.ScaleTo(countDownObj, iTween.Hash("x", 0,"y", 0, "delay", 0.5, "time", 0.5, "easeType", "easeInOutQuad"));
countDownObj.SetActive(false);