Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Inflate: MonoBehaviour {
- // List of balloons, can be filled in the inspector
- public List<Rigidbody2D> balloons;
- // List of scales to reach
- private List<Vector3> goalScale;
- // Speed of the interpolation (Default = 0.1, but can be modified in the inspector)
- public float speed = 0.1f;
- // Use this for initialization
- void Start () {
- // Initialize the goalScales and attribute to each balloon
- goalScale = new List<Vector3> ();
- for (int i = 0; i<balloons.Count; i++) {
- goalScale.Add(balloons[i].transform.localScale);
- }
- }
- // Update is called once per frame
- void Update () {
- // Get User Input
- Inputs ();
- // Apply new scale to each balloon (Lerp to be more fluid)
- for (int i = 0; i<balloons.Count; i++) {
- // Degonfle ici
- if (goalScale[i].x > 0.625f) {
- //proportional
- goalScale[i] -= goalScale[i]/20 * Time.deltaTime;
- //fixed
- // goalScale[i] -= new Vector3 (0.01f,0.1f,0.1f) * Time.deltaTime;
- }
- balloons[i].transform.localScale = Vector3.Lerp(balloons[i].transform.localScale, goalScale[i], speed);
- balloons[i].mass = balloons[i].transform.localScale.x / 0.15f;
- }
- }
- // To inflate
- void InflateBalloon (int balloonNo) {
- // If the balloon is not too big
- if (balloons [balloonNo].transform.localScale.x <= 1.9f) {
- // Change its goal scale
- goalScale [balloonNo] = balloons [balloonNo].transform.localScale + new Vector3 (0.03f, 0.03f, 0.03f);
- }
- }
- void Inputs() {
- if (Input.GetKeyDown(KeyCode.W)) {
- // In a list, first element is 0
- InflateBalloon(0);
- }
- if (Input.GetKeyDown(KeyCode.M)) {
- InflateBalloon(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement