Skip to content

Commit

Permalink
drop zone
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamReifsneider committed Jul 12, 2020
1 parent d48cb3c commit 8826284
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 173 deletions.
59 changes: 59 additions & 0 deletions BOX-BUX/Assets/Scripts/DropZone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using UnityEngine;

public class DropZone : MonoBehaviour
{
private class ChangingState
{
public float countdown;
public bool changing;

public ChangingState(float countdown, bool changing)
{
this.countdown = countdown;
this.changing = changing;
}
}

public ChangeType changeType;
public float secondsToChange = 0.5f;
private Dictionary<Pickable, ChangingState> countdowns = new Dictionary<Pickable, ChangingState>();

private void Update()
{
foreach(var box in countdowns.Keys.ToList())
{
var state = countdowns[box];
if (!state.changing)
{
countdowns.Remove(box);
continue;
}
state.countdown -= Time.deltaTime;
if(state.countdown <= 0)
{
countdowns.Remove(box);
ModificationSystem.MakeChange(box, changeType);
}
}
}

public void OnTriggerStay(Collider other)
{
Triggerable triggerable = other.GetComponent<Triggerable>();
if (triggerable == null)
{
return;
}
Pickable toChange = triggerable.asPickable();

if (!countdowns.ContainsKey(toChange))
{
countdowns.Add(toChange, new ChangingState(secondsToChange, toChange.holder.held != toChange));
}
}
}
11 changes: 11 additions & 0 deletions BOX-BUX/Assets/Scripts/DropZone.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8826284

Please sign in to comment.