private IEnumerator IsAnythingMoving(MovingScript mS) { while (mS.amIMoving) { // Debug.Log(mS.amIMoving + "amimoving"); if (!mS.amIMoving) { // CheckState(); } yield return(new WaitForEndOfFrame()); } StartCoroutine(CheckState()); // Debug.Log("isanythingmoving : tehty"); }
void AddBlock() { int size = AllObjects.Count; if (size == 0) { Instantiate(first_block).name = "block_0"; AllObjects.Add(GameObject.Find("block_0")); GameObject.Find("block").GetComponent <SpriteRenderer>().enabled = false; MovingScript other = AllObjects[size].GetComponent <MovingScript>(); if (other != null) { Destroy(other); } } else if (size == 1) { Instantiate(AllObjects[0]).name = "block_" + size;; AllObjects.Add(GameObject.Find("block_" + size)); var renderer = (SpriteRenderer)AllObjects[1].GetComponent("SpriteRenderer"); renderer.sprite = Resources.LoadAssetAtPath <Sprite>("Assets/Sprites/snake.png"); renderer.sortingOrder = 9; MovingScript other = AllObjects[size].GetComponent <MovingScript>(); if (other != null) { Destroy(other); } } else { Instantiate(AllObjects[1]).name = "block_" + size;; AllObjects.Add(GameObject.Find("block_" + size)); MovingScript other = AllObjects[size].GetComponent <MovingScript>(); if (other != null) { Destroy(other); } } }
void Start() { player = transform.parent.GetComponent <MovingScript>(); }
private void FindGum(int i) { bool listBool = GetList(); // Debug.Log("gums " + gums.Count); // int targetY, targetX; switch (i) { case 0: //liikutti alas foreach (GameObject gum in gums) { if (gum.GetComponent <LocationHolder>().yCoord - moveY == -1 && gum.GetComponent <LocationHolder>().xCoord == moveX) { MovingScript mScript = gum.GetComponent <MovingScript>(); otherTargetedObject = gum; otherOriginalPosition = otherTargetedObject.transform.position; otherX = otherTargetedObject.GetComponent <LocationHolder>().getX(); otherY = otherTargetedObject.GetComponent <LocationHolder>().getY(); StartCoroutine(mScript.MoveTowardsThis(1, 1)); StartCoroutine(IsAnythingMoving(mScript)); // CheckState(); } } break; case 1: //liikutti ylös foreach (GameObject gum in gums) { if (gum.GetComponent <LocationHolder>().yCoord - moveY == 1 && gum.GetComponent <LocationHolder>().xCoord == moveX) { MovingScript mScript = gum.GetComponent <MovingScript>(); otherTargetedObject = gum; otherOriginalPosition = otherTargetedObject.transform.position; otherX = otherTargetedObject.GetComponent <LocationHolder>().getX(); otherY = otherTargetedObject.GetComponent <LocationHolder>().getY(); StartCoroutine(mScript.MoveTowardsThis(0, 1)); StartCoroutine(IsAnythingMoving(mScript)); // CheckState(); } } break; case 2: //liikutti vasemmalle foreach (GameObject gum in gums) { if (gum.GetComponent <LocationHolder>().xCoord - moveX == -1 && gum.GetComponent <LocationHolder>().yCoord == moveY) { MovingScript mScript = gum.GetComponent <MovingScript>(); otherTargetedObject = gum; otherOriginalPosition = otherTargetedObject.transform.position; otherX = otherTargetedObject.GetComponent <LocationHolder>().getX(); otherY = otherTargetedObject.GetComponent <LocationHolder>().getY(); StartCoroutine(mScript.MoveTowardsThis(3, 1)); StartCoroutine(IsAnythingMoving(mScript)); // CheckState(); } } break; case 3: //liikutti oikealle foreach (GameObject gum in gums) { if (gum.GetComponent <LocationHolder>().xCoord - moveX == 1 && gum.GetComponent <LocationHolder>().yCoord == moveY) { MovingScript mScript = gum.GetComponent <MovingScript>(); otherTargetedObject = gum; otherOriginalPosition = otherTargetedObject.transform.position; otherX = otherTargetedObject.GetComponent <LocationHolder>().getX(); otherY = otherTargetedObject.GetComponent <LocationHolder>().getY(); StartCoroutine(mScript.MoveTowardsThis(2, 1)); StartCoroutine(IsAnythingMoving(mScript)); // CheckState(); } } break; } }