The code in this chapter

Let's take a look at the code again to make sure we are on the same page.

The code for Collectable.cs is as follows:

using UnityEngine; 
using System.Collections; 
 
public class Collectable : MonoBehaviour { 
   
  bool isCollected = false; 
 
  void Show() { 
    this.GetComponent<SpriteRenderer>().enabled = true; 
    this.GetComponent<CircleCollider2D>().enabled = true; 
    isCollected = false; 
  } 
 
  void Hide() { 
    this.GetComponent<SpriteRenderer>().enabled = false; 
    this.GetComponent<CircleCollider2D>().enabled = false; 
  } 
 
 
  void Collect() { 
 
    isCollected = true; 
    Hide(); 
    GameManager.instance.CollectedCoin(); 
  } 
 
  void OnTriggerEnter2D(Collider2D other) { 
     
    if (other.tag == "Player") { 
      Collect(); 
    } 
  }   
} 

Here is the code for HealthPoint:

 using UnityEngine ...

Get Learning C# 7 By Developing Games with Unity 2017 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.