title: Scoring points using triggers in Unity
body: <p>I want that whenever my player passes through a particular portion of my obstacle it should add 2 points to the score. In order to do this I've made a child of the obstacle. This child contains the box collider which covers that particular portion of the obstacle (I've switched on the Is Trigger in Unity).</p>
  <p>Code on child having trigger -</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Score : MonoBehaviour
  {
      float points;
      
      void Start()
      {
      
      }
  
      void Update()
      {
          Debug.Log(points);
      }
      void OnTriggerExit2D(Collider2D other)
     {
          points += 2f;
     }
  }
  </code></pre>
  <p>The problem is that in the console the points are showing 0s and 2s only like this -</p>
  <p><a href="https://i.stack.imgur.com/iyD1W.png" rel="nofollow noreferrer">Console</a></p>
  <p>While it should be 0, 2, 4, 6... after passing the obstacle.</p>
  <p>Also clones of the original obstacle are being created, i.e. I pass through a new clone each time; in case this is causing the problem.</p>