Created
May 18, 2021 14:51
-
-
Save TheCuttlefish/b427bea9d7ef3445121c98dffc48f066 to your computer and use it in GitHub Desktop.
Can Script - sprite swap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CanScript : MonoBehaviour | |
{ | |
public int dropsNum = 0; | |
public GameObject water; | |
bool warning = false; | |
float warningTimer = 0; | |
public List<Sprite> canSprites = new List<Sprite>(); | |
void Start() | |
{ | |
water.transform.localScale = new Vector3(1, 0.25f * dropsNum, 1); | |
} | |
void Update() | |
{ | |
//water.transform.localScale = new Vector3(1, 0.25f * dropsNum, 1); | |
if (dropsNum < 4) GetComponent<SpriteRenderer>().sprite = canSprites[dropsNum]; | |
else warning = true; | |
if (warning == true) | |
{ | |
warningTimer += Time.deltaTime; //seconds | |
if (warningTimer > 0) GetComponent<SpriteRenderer>().color = Color.red; | |
if (warningTimer > 2) GetComponent<SpriteRenderer>().color = Color.yellow; | |
if (warningTimer > 3) | |
{ | |
GetComponent<SpriteRenderer>().color = Color.white; | |
warning = false; | |
warningTimer = 0; | |
dropsNum = 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment