I want to create a scoring system so that every time a set color collides with another set color you get one point and the colorObject is destroyed i.e blue ball and a blue wall however I created the scripts for gameobject(destroy) for each color in 4 different scripts so I was wondering if it is possible that if a blue ball collides with a blue wall in the if statement I could write successfulCollision; and then in my score script I could use some kind of code to add a point for every successfulCollision;
So right now it looks like your script detects when the correctly coloured ball hits the correctly coloured wall, so then you just need a script to keep track of the score, with a method that can be called to increase it. Something like:
using UnityEngine;
using System.Collections;
public class ScoreKeeper : MonoBehaviour
{
public int score;
void Start()
{
score = 0;
}
public void IncreaseScore()
{
score++;
}
}
Attach this to a score-keeping GameObject and create references to the script in each of your collision scripts. Then you can do this:
void OnCollisionEnter2D(Collision2D collision2D)
{
if (collision2D.transform.name == "RedWall")
{
PlaySound(0);
Destroy(gameObject);
scoreKeeper.IncreaseScore();
}
//...
}
Hope this helps.