// Update is called once per frame void Update() { Thought thought = thoughtMenu.currentThought; if (thought == null) { // freeze when thought is chosen, and still jumping if (!player.grounded) { gameObject.GetComponent <SpriteRenderer>().enabled = true; transform.position = previousPosition; } else { gameObject.GetComponent <SpriteRenderer>().enabled = false; } return; } gameObject.GetComponent <SpriteRenderer>().enabled = true; float zeroY = runManager.runState.height; float minY = zeroY + ActivityPlatform.PowerToYDiff(thought.minJumpPower); float maxY = zeroY + ActivityPlatform.PowerToYDiff(thought.maxJumpPower + 1); float range = maxY - minY; float period = .5f; // number of seconds per cycle // move position up and down until thought has been chosen, then freeze float offset = range == 0 ? 0 : (Time.time * range / period) % range; transform.position = new Vector2(transform.parent.position.x - 0.3f, minY + offset - ActivityPlatform.platformThickness); previousPosition = transform.position; }
// instantiate a new activity platform private void SpawnPlatform(Activity activity, int jumpNumber) { int yDiff = ActivityPlatform.PowerToYDiff(jumpNumber); GameObject platform = Instantiate(platformPrefab); platform.GetComponent <ActivityPlatform>().Initialize(activity, yDiff, jumpNumber); // add it to list of prospective platforms in runState runState.spawnedPlatforms.Add(platform.GetComponent <ActivityPlatform>()); }