Created
April 20, 2017 07:20
-
-
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
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 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