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 think too hard about Layers.
this script subtracts for Triple 20
using UnityEngine;
using System.Collections;
public class subScoreTrip20 : MonoBehaviour
{
public int scoreValue;
public bool unhit = true;//
public Transform prefab;
void Start ()
{
}
void OnCollisionEnter(Collision other)
{
if(other.collider.tag == ("dart"))//&& unhit)/////////////
{
Instantiate (prefab, transform.position, transform.rotation);
//CameraShake script;
//script = Object.GetComponent<CameraShake>();
//script.enabled = true;
ScoreManager.score -= scoreValue = 60;
audio.Play ();
other.rigidbody.isKinematic = true;
}
//unhit = false;///////
//Destroy(gameObject, 1);///////
}
}
and the ScoreManager script
using UnityEngine;
using UnityEngine.UI; // This is the call for the new UI, this MUST be in here for this to work.
using System.Collections;
//[RequireComponent(typeof(AudioSource))]
public class ScoreManager : MonoBehaviour
{
public static int score = 501; // The player's score.
public static int oldScore = 501;
Text text; // Reference to the Text component.
void Awake ()
{
// Set up the reference.
text = GetComponent <Text> ();
// Reset the score.
score = 501;
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
if(score < 0 || score == 1)
{
//AudioSource audio = GetComponent<AudioSource>();
audio.Play ();
score = oldScore;
}
else
{
oldScore = score;
}
text.text = " " + score;
oldScore = score;
if(score == 0)
{
//audio.Play ();
Debug.Log ("You Win");
Application.LoadLevel("L2");
}
}
}