Skip to content

Commit

Permalink
added playing sounds for plants
Browse files Browse the repository at this point in the history
  • Loading branch information
Amatsugu committed Aug 20, 2024
1 parent 83a438d commit 447ca7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Assets/Scripts/GameData/PlantDefination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class PlantDefination : ScriptableObject
public float unitCost;
public float unitSell;
public bool isEvil;
public AudioClip plantingSound;
public AudioClip harvestingSound;
public ResourceIdentifier[] yeild;

public Plant CreatePlant(Transform location)
Expand Down
14 changes: 12 additions & 2 deletions Assets/Scripts/UX/PlanterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

using UnityEngine;

[RequireComponent(typeof(GameManager))]
[RequireComponent(typeof(GameManager)), RequireComponent(typeof(AudioSource))]
public class PlanterController : MonoBehaviour
{
public enum UIState
Expand All @@ -17,14 +17,15 @@ public enum UIState
}

public UIState state;

public AudioClip wateringSound;
public PlantDefination[] plants;

[HideInInspector]
public PlantDefination _selectedPlant;


private Dictionary<ResourceType, List<ResourceType>> _seedLookup;
private AudioSource _audioSource;
// Update is called once per frame
private void Update()
{
Expand All @@ -42,6 +43,9 @@ private void Update()

private void Awake()
{
_audioSource = GetComponent<AudioSource>();
if(_audioSource == null)
_audioSource = gameObject.AddComponent<AudioSource>();
_seedLookup = new Dictionary<ResourceType, List<ResourceType>>();
foreach (var plant in plants)
{
Expand Down Expand Up @@ -74,10 +78,14 @@ private void ProcessPlanterSelection()
if (planter.Crop.IsHarvestable)
{
planter.Harvest();
if(planter.Crop.plant.harvestingSound != null)
_audioSource.PlayOneShot(planter.Crop.plant.harvestingSound);
}
else
{
planter.Crop.Water(5);
if(wateringSound != null)
_audioSource.PlayOneShot(wateringSound);
}

return;
Expand All @@ -89,6 +97,8 @@ private void ProcessPlanterSelection()
if(GameManager.ResourcesService.SpendResources((_selectedPlant.seedResource, 1)))
{
planter.Plant(_selectedPlant);
if(_selectedPlant.plantingSound != null)
_audioSource.PlayOneShot(_selectedPlant.plantingSound);
}
}

Expand Down

0 comments on commit 447ca7d

Please sign in to comment.