Going to get a tumour from this score system xD

So I think I made a big mistake with how I did this somewhere, but through a couple days of toying around and trying to get my score to work properly, I’ve finally gotten the scoreboxes to loop back with the obstacles in my game perfectly. The problem now is that when I hit a scorebox, rather than scoring a single point I’m gaining around 9 each time I go through one. I thought my code had an answer for this, but it doesn’t seem to be working. What I’m thinking is that because I have three different score related scripts throughout my game, maybe there’s some interference or something but I can’t for the life of me discern what could be causing it.

My first script is in the script for my character:

 bool ScoreActive = true;

void OnTriggerEnter2D(Collider2D collider)  {
		
		if (godMode)
			
			return;
		
		if (collider.tag == "ScoreBox") {
			
			if (ScoreActive == true) {
				
				Score.AddPoint ();
				
				ScoreActive = false;
				
			}
			
		} else {

			animator.SetTrigger ("Dead");
			dead = true;
			
		}
		
	}
}

The second code is my score script which I have set into a GUIText, obviously displaying the score to the player:

	static int score = 0;
	static int highScore = 0;

	static public void AddPoint() {
				score++;

				if(score > highScore) {
						highScore = score;
				}
		}

	void Start(){
		score = 0;
				highScore = PlayerPrefs.GetInt ("highScore", 0);
		}

	void OnDestroy() {
				PlayerPrefs.SetInt ("highScore", highScore);
		}
	// Update is called once per frame
	void Update () {
		guiText.text = "Score: " + score + "\nHigh Score: " + highScore;
	}
}

And finally I have another score script in the scorebox itself, which is where I think the problem may be coming from:

	void OnTriggerEnter2D(Collider2D collider) {
		if(collider.tag == "Player") {
			Score.AddPoint();
			}
		}
	}

I’ve attempted to disable the last code and the problem still persisted, so I’m planning on getting rid of it but I’ve put it off just incase you guys think I should keep it or something. The code in my player is needed as it is what distinguishes that the score box isn’t a normal obstacle and prevents the player from dying when hitting hit.

Any help would be much appreciated!

Problem is more likely in your movement code than your trigger code; off-hand, I’d guess you were moving colliders in Update instead of FixedUpdate.

I thought it might’ve been to at first, but the looping is being done by a looper which is following behind the player, and the code for the looper itself actually uses a OnEnter2D rather than update/fixedupdate.

Okay so I tried removing all mention of the score from my player and just leaving it as “if he’s hitting the scorebox, don’t kill him” Then I moved my score code to the other code which now looks like this:

using UnityEngine;
using System.Collections;

public class ScorePoint : MonoBehaviour {

	bool ScoreActive = true;

	void OnTriggerEnter2D(Collider2D collider) {
		if(collider.tag == "Player") {
			if(ScoreActive == true){
			Score.AddPoint();
				ScoreActive = false;
			}
			}
		}

	void OnTriggerExit2D(Collider2D collider) {
				ScoreActive = true;
	}
}

And it’s actually working much better, minus a few cases.
After scoring the first six points (the number of points possible before the boxes have all been hit at least once), the bool is only SOMETIMES being set back to true. Most times, it works, but about 30% of the time, no score is added. Everything else is working just fine, but I need a 100% consistency with the variable being toggled back to true.
Thanks for any help!

[EDIT] Nevermind guys I got it all figured out. Thanks for the help though! Sorry for posting so much :stuck_out_tongue: