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”);
- }
- }
- }