Skip to content

Instantly share code, notes, and snippets.

@halzate93
Last active October 25, 2017 21:12
Show Gist options
  • Save halzate93/a6726fa2e51dbb0f4825dddeee8aae21 to your computer and use it in GitHub Desktop.
Save halzate93/a6726fa2e51dbb0f4825dddeee8aae21 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class piler : MonoBehaviour
{
[SerializeField]
private GameObject[] dishesPile;
private AudioSource audioSource;
private float volLowRange = .5f;
private float volHighRange = 1.0f;
private int currentDishPosition;
public AudioClip shootSound;
public AudioClip ding;
private void Awake()
{
audioSource = GetComponent<AudioSource>();
}
public void IncreasePile() // This function is called by another who checks if the player grab a dish.
{
dishesPile[currentDishPosition].SetActive(true);
currentDishPosition++;
if (currentDishPosition == 4) //Haga que esto sea parametrizado
{ // le sobran estos corchetes
DestroyPile();
}
}
public void DestroyPile()
{
float vol = UnityEngine.Random.Range(volLowRange, volHighRange); //choose a random volume between Ranges to be less repetitive.
audioSource.PlayOneShot(shootSound, vol);
//Ese pedazo puede ser otra funcion ^
for (int i = 0; i < dishesPile.Length; i++)
{
dishesPile[i].SetActive(false);
currentDishPosition = 0;
}
Manager.Instance.LoseLifes(1); //The game manager(Singleton) updates the score.
return; // este return le sobra durísimo
}
public void CleanDishes ()
{
float vol = Random.Range(volLowRange, volHighRange);
audioSource.PlayOneShot(ding, vol);
// Este pedazo se parece mucho al otro que le dije que podía ser una funcion.
for (int i = 0; i < dishesPile.Length; i++)
{
dishesPile[i].SetActive(false);
Manager.Instance.AddScore(10 * currentDishPosition);
currentDishPosition = 0;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "DishWasher")
{
CleanDishes();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment