void Update() { if (isRunning) { CodeAnimation c = CodeAnimationController.instance.GetAnimation(this.gameObject); if (c != null) { GameManager.instance.tempWorldSpeed = ((FloatLerp)CodeAnimationController.instance.GetAnimation(this.gameObject)).GetProgress(); } } else { } }
public override void Reset(CodeAnimation c) { FloatLerp vs = (FloatLerp)c; if (!done) { return; } paused = false; done = false; original = vs.original; newNumber = vs.newNumber; journeyTime = vs.journeyTime; startTime = Time.time; t = 0; currentNumber = original; }
void Update() { if (firstFrame) { AudioManager.instance.SetCorrectVolume(gameObject, true); firstFrame = false; } if (levelBreakpoints.Length < 3) { Debug.LogError("Levelbreakpoints has to be more than three long! Changing to default values."); levelBreakpoints = new int[] { 30, 60, 100 }; } //Increase speed if ((score >= levelBreakpoints[0] && gameLevel == 0) || (score >= levelBreakpoints[1] && gameLevel == 1) || (score >= levelBreakpoints[2] && gameLevel == 2)) { CodeAnimationController.instance.Add(new FloatLerp(originalWorldMoveSpeed, originalWorldMoveSpeed + 0.5f, 100f, this.gameObject)); gameLevel++; } //Animate the speed increase CodeAnimation c = CodeAnimationController.instance.GetAnimation(this.gameObject); if (c != null) { originalWorldMoveSpeed = ((FloatLerp)CodeAnimationController.instance.GetAnimation(this.gameObject)).GetProgress(); } if (tempWorldSpeed > 0f) { worldMoveSpeed = tempWorldSpeed; } else { worldMoveSpeed = originalWorldMoveSpeed; } if (!gameOver) { UIManager.instance.OnGameRunning("Score: " + score, "Highscore: " + highscore, "Worms: " + currency); } world.GetComponent <World> ().MoveWorld(worldMoveSpeed); }
public override void Reset(CodeAnimation c) { VectorSlerp vs = (VectorSlerp)c; if (newVector3 == null || vs.newVector3 == newVector3) { return; } paused = false; done = false; originalVector3 = vs.originalVector3; newVector3 = vs.newVector3; journeyTime = vs.journeyTime; startTime = Time.time; transform = vs.transform; type = vs.type; t = 0; currentVector = originalVector3; }
public void Add(CodeAnimation anim) { bool found = false; //If someone tries to add a new animation of a gameobject that already has an animation, //call it's reset method which will evaluate if it should reset instead of always adding //or removing objects from the list foreach (CodeAnimation a in animations) { if (a.g == anim.g) { a.Reset(anim); found = true; break; } } if (!found) { animations.Add(anim); } }
public virtual void Reset(CodeAnimation c) { }
void FixedUpdate() { //Rotation float xSpeed = GameManager.instance.worldMoveSpeed; float rotation = transform.parent.rotation.z; //Multiple touches, move straight, nothing in the y axis if (Input.GetKey(KeyCode.B) || Input.touchCount > 1 || (Input.GetMouseButton(0) && Input.GetMouseButton(1))) { Rotate(0f); isRotated = false; } //The player is pressing down and should go up and rotate up else if ((Input.GetKey(KeyCode.Space) || (Input.touchCount == 1 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) || (Input.mousePresent && Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject()))) { rgdbd2d.velocity = Vector3.zero; rgdbd2d.MovePosition(new Vector2(0, rgdbd2d.position.y + speedDownMovement)); //Calculate the rotation float rad = Mathf.Atan2(speedUpMovement, xSpeed * Time.deltaTime); float deg = Mathf.Rad2Deg * rad; //Get the height when the player is rotated distance = Mathf.Cos((Mathf.PI / 2) - rad) * (originalSpriteWidth / 2); if (!isTouchingTop()) { Rotate(deg); isRotated = true; } else { Rotate(0f); rgdbd2d.MovePosition(new Vector2(0, rgdbd2d.position.y)); isRotated = false; } } else //Player is not pressing down and the "gravity" should take over, pulling the character down { rgdbd2d.MovePosition(new Vector2(0, rgdbd2d.position.y - speedUpMovement)); //Calculate the rotation float rad = Mathf.Atan2(speedDownMovement, xSpeed * Time.deltaTime); float deg = Mathf.Rad2Deg * rad - 90; //Get the height when the player is rotated distance = Mathf.Cos((Mathf.PI / 2) - rad) * (originalSpriteWidth / 2); if (!isTouchingBottom()) { Rotate(deg); isRotated = true; } else { Rotate(0f); rgdbd2d.MovePosition(new Vector2(0, rgdbd2d.position.y)); isRotated = false; } } //Rotate slowly with an animation CodeAnimation c = CodeAnimationController.instance.GetAnimation(this.gameObject); Vector3 rot; if (c != null && c is VectorSlerp) { rot = ((VectorSlerp)c).GetProgress(); } else { rot = Vector3.zero; } if (rot.z < 0) { rot = new Vector3(rot.x, rot.y, rot.z + 90); } float currentDistance = Mathf.Cos((Mathf.PI / 2) - (Mathf.Deg2Rad * rot.z)) * (originalSpriteWidth / 2); trail.OnUpdate(new Vector3(rgdbd2d.position.x, rgdbd2d.position.y, 0f), isRotated, currentDistance); //Change speed for the walking-animation if the player is rotated if (isRotated) { GetComponent <Animator>().speed = animationSpeedClimbing; } else { GetComponent <Animator>().speed = 1f; } }