Skip to content

Instantly share code, notes, and snippets.

@troys-code
Created April 20, 2017 07:20
Show Gist options
  • Select an option

  • Save troys-code/7a2ff7b473bff13e476750914a7b0db7 to your computer and use it in GitHub Desktop.

Select an option

Save troys-code/7a2ff7b473bff13e476750914a7b0db7 to your computer and use it in GitHub Desktop.
Gathering resource from fixed location. Script increases resource every second the player is colliding with me
using System.Collections;
// using System.Collections.Generic;
using UnityEngine;
public class GetGoop : MonoBehaviour {
Coroutine mining;
void OnTriggerEnter (Collider coll) {
var GO = coll.gameObject;
if (GO.tag == "Player") {
// mine that goop mound
mining = StartCoroutine(TakeGoop());
}
}
void OnTriggerExit (Collider coll) {
var GO = coll.gameObject;
if (GO.tag == "Player") {
// stop mining goop
StopCoroutine(mining);
}
}
IEnumerator TakeGoop () {
// initial delay
yield return new WaitForSeconds(0.3f);
// add goop loop
while (true) {
yield return new WaitForSeconds(0.5f);
GlobalState.AddGoop(1);
yield return new WaitForSeconds(0.5f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment