IEnumerator DoAttack() { attacking = true; Vector3 startPos = transform.position; Vector3 endPos = transform.position + new Vector3(0, attackDistance, 0); while (transform.position.y - startPos.y < attackDistance) { if (!pausing) { Vector2DUtils.MoveToSmoothly(transform, endPos, attackSpeed); } yield return(null); } while (transform.position.y - startPos.y > Mathf.Epsilon) { if (!pausing) { Vector2DUtils.MoveToSmoothly(transform, startPos, attackSpeed); } yield return(null); } attacking = false; animRun.StartPlay(); tracer.OnResume(); }
IEnumerator DoUpdate(Vector3 center, Vector2 size, AnimationDoneCallBack callback, float animateTime) { Vector2[] scope = Vector2DUtils.GetScreenScope(); //to radius size = size * 0.5f; Vector3 lStart = new Vector3(scope[0].x - lr.bounds.size.x * 0.5f, center.y, center.z); Vector3 lEnd = lStart; lEnd.x = center.x - size.x - lr.bounds.size.x * 0.5f; Vector3 tStart = new Vector3(center.x, scope[1].y + tr.bounds.size.y * 0.5f, center.z); Vector3 tEnd = tStart; tEnd.y = center.y + size.y + tr.bounds.size.y * 0.5f; Vector3 rStart = new Vector3(scope[1].x + rr.bounds.size.x * 0.5f, center.y, center.z); Vector3 rEnd = rStart; rEnd.x = center.x + size.x + rr.bounds.size.x * 0.5f; Vector3 bStart = new Vector3(center.x, scope[0].y - br.bounds.size.y * 0.5f, center.z); Vector3 bEnd = bStart; bEnd.y = center.y - size.y - br.bounds.size.y * 0.5f; lr.transform.position = lStart; tr.transform.position = tStart; rr.transform.position = rStart; br.transform.position = bStart; if (Math.Abs(animateTime) > Mathf.Epsilon) { float lSpeed = ((lEnd - lStart) / animateTime).magnitude; float tSpeed = ((tEnd - tStart) / animateTime).magnitude; float rSpeed = ((rEnd - rStart) / animateTime).magnitude; float bSpeed = ((bEnd - bStart) / animateTime).magnitude; float timeUsed = 0; while (timeUsed < animateTime) { if (!pausing) { timeUsed += Time.deltaTime; Vector2DUtils.MoveToSmoothly(lr.transform, lEnd, lSpeed); Vector2DUtils.MoveToSmoothly(tr.transform, tEnd, tSpeed); Vector2DUtils.MoveToSmoothly(rr.transform, rEnd, rSpeed); Vector2DUtils.MoveToSmoothly(br.transform, bEnd, bSpeed); } yield return(null); } } lr.transform.position = lEnd; tr.transform.position = tEnd; rr.transform.position = rEnd; br.transform.position = bEnd; callback(center, size); }
IEnumerator DoMyUpdate() { while (true) { if (null == GameController.GetSingleton() || null == GameController.GetSingleton().levelsController || null == GameController.GetSingleton().levelsController.eggController) { //for design yield return(null); } Vector3 pos = GameController.GetSingleton().levelsController.eggController.transform.position; float dis = Mathf.Abs((pos - transform.position).magnitude); //Log.Debug ("E1 see egg {0}",dis); if (sensibleDistance > dis) { Log.Debug("E1 see egg {0}", dis); //start fly animIdle.StopPlay(); animFly.StartPlay(); GameController.singleton.audioController.PlayBirdFly(); break; } yield return(null); } while (true) { if (!Vector2DUtils.IsInScreen(transform.position)) { Log.Debug("E1 out of screen"); gameObject.SetActive(false); yield break; } if (_flyIndex > flyPoints.Length - 1) { gameObject.SetActive(false); break; } Vector3 fp = flyPoints [_flyIndex]; Vector2DUtils.MoveToSmoothly(transform, fp, flySpeed); if (fp == transform.position) { _flyIndex++; } yield return(null); } }
public void Update() { if (!started) { return; } if (_pausing) { return; } Vector3 fp = movePoints [movingIndex]; Vector3 v = Vector2DUtils.MoveToSmoothly(transform, fp, moveSpeed); // Log.Debug ("moving... {0},{1},{2},{3},{4}",movingIndex,fp,v,transform.position,moveSpeed); int reachedPoint = -1; if ((Vector2)fp == (Vector2)transform.position) { // Log.Debug ("OnReachPosition {0},{1}",fp , transform.position); OnReachPosition(movingIndex, fliping); reachedPoint = movingIndex; if (!fliping) { if (movingIndex == movePoints.Length - 1) { HandleFlip(); } else { movingIndex++; } } else { if (movingIndex == 0) { HandleFlip(); } else { movingIndex--; } } } PostUpdate(reachedPoint); }
IEnumerator DoJump(Vector3 pos) { while (transform.position != pos) { if (!pausing) { Vector2DUtils.MoveToSmoothly(transform, pos, activeJumpSpeed); } yield return(null); } animJump.StopPlay(); animClimb.StartPlay(); Transform egg = GameController.GetSingleton().levelsController.eggController.transform; tracer.target = egg; tracer.Start(); Log.Debug("E9 start trace..."); }
IEnumerator DoUpdate(float speed, Vector3 target) { animator.StartPlay(); while (true) { transform.eulerAngles = startAngulars; if (target.x < transform.position.x) { Vector2DUtils.Flip(transform); } while (transform.position != target) { // Log.Debug ("gooooo : {0},{1}",transform.position , target); if (Vector2DUtils.IsOutsideScreen(transform.position, Direction2D.up)) { // Log.Debug ("{0} outof screen.",gameObject.name); StopAct(); yield break; } if (!pausing) { Vector2DUtils.MoveToSmoothly(transform, target, speed); } yield return(null); } Vector2[] scope = Vector2DUtils.GetScreenScope(); float xbound = render.bounds.size.x * .5f; float rightX = scope [1].x + xbound + 10; float leftX = scope [0].x - xbound - 10; target.x = UnityEngine.Random.Range(leftX, rightX); target.y = UnityEngine.Random.Range(scope[0].y, scope[1].y); // Log.Debug ("move to new pos : {0}",target); } }