Detect collision only once when collider hits 2 objects at the same time

Detect collision only once when collider hits 2 objects at same time
I have a dart game that has a OnCollisionEnter() script on every collider. example single20 has a collider with script that tells my ScoreManager script to change text from 501subtract 20 which equals 481 which does as it should.Triple 20 has its own script that subtracts 60 as it should…Double 20 has its own script that subtracts 40 as it should.I have this on every number and bullseye.

The problem is that the dart I am using has a Sphere collider which hits 2 colliders at the same time on the edges so it scores from 2 colliders at the same time when i only want to score from one collider at a time.I know about Layers, but the colliders I think have to be in the same Layer unless I am thinking too hard about Layers.

this script subtracts for Triple 20

  • usingUnityEngine;
  • usingSystem.Collections;
  • publicclass subScoreTrip20 :MonoBehaviour
  • {
  • publicint scoreValue;
  • publicbool unhit =true;//
  • publicTransform prefab;
  • voidStart()
  • {
  • }
  • voidOnCollisionEnter(Collision other)
  • {
  • if(other.collider.tag ==(“dart”))//&& unhit)/////////////
  • {
  • Instantiate(prefab, transform.position, transform.rotation);
  • //CameraShake script;
  • //script = Object.GetComponent();
  • //script.enabled = true;
  • ScoreManager.score -= scoreValue =60;
  • audio.Play();
  • other.rigidbody.isKinematic =true;
  • }
  • //unhit = false;///////
  • //Destroy(gameObject, 1);///////
  • }
  • }

and the ScoreManager script

  • usingUnityEngine;
  • usingUnityEngine.UI;// This is the call for the new UI, this MUST be in here for this to work.
  • usingSystem.Collections;
  • //[RequireComponent(typeof(AudioSource))]
  • publicclassScoreManager:MonoBehaviour
  • {
  • publicstaticint score =501;// The player’s score.
  • publicstaticint oldScore =501;
  • Text text;// Reference to the Text component.
  • voidAwake()
  • {
  • // Set up the reference.
  • text =GetComponent();
  • // Reset the score.
  • score =501;
  • }
  • voidUpdate()
  • {
  • // Set the displayed text to be the word “Score” followed by the score value.
  • if(score <0|| score ==1)
  • {
  • //AudioSource audio = GetComponent();
  • audio.Play();
  • score = oldScore;
  • }
  • else
  • {
  • oldScore = score;
  • }
  • text.text =" "+ score;
  • oldScore = score;
  • if(score ==0)
  • {
  • //audio.Play ();
  • Debug.Log(“You Win”);
  • Application.LoadLevel(“L2”);
  • }
  • }
  • }

please use [code ][/code ] tags when pasting code into the forums, there is a sticky on them at the top of the scripting forum

I think you’re going to need to think about this from the other way around. Rather than having the board segments informing the scoring system they’ve been hit you’ll need to have the dart do it.

The dart can then check what it has hit, figure out which it should be scored against based on whatever logic you want to use (highest value, or some calculation based on hit.point etc.).