// Use this for initialization void Start() { transform.parent.SetParent(GameObject.Find("-Meshes").transform); if (GameEvent.Instance.GameStatus == GameState.Playing) { StartCoroutine(StartMove()); } else { LevelData.AddTargetCount(1); } }
// Update is called once per frame IEnumerator StartMove() { GetComponent <SpriteRenderer> ().sortingLayerName = "UI layer"; LevelData.AddTargetCount(1); AnimationCurve curveX = new AnimationCurve(new Keyframe(0, transform.position.x), new Keyframe(0.5f, targetPos.x)); AnimationCurve curveY = new AnimationCurve(new Keyframe(0, transform.position.y), new Keyframe(0.5f, targetPos.y)); curveY.AddKey(0.2f, transform.position.y - 4); float startTime = Time.time; Vector3 startPos = transform.position; float speed = Random.Range(0.4f, 0.6f); float distCovered = 0; while (distCovered < 1) { distCovered = (Time.time - startTime) * speed; transform.position = new Vector3(curveX.Evaluate(distCovered), curveY.Evaluate(distCovered), 0); yield return(new WaitForEndOfFrame()); } Destroy(gameObject); }