Hi gang
I am working on a game that I would like to add a chaining system to my score where if a player hits an object of the same colour, it sequentially increases the multiplier, and if they hit an object of a different colour, the multiplier resets and begins with the new object as the starting base.
So if hit red object, multiply x 2, next hit if red, multiply by 3, next hit if blue, reset multiplier to blue as the chain start.
This script is attached to the projectile and the scoring all works fine except for the chaining does not work at all.
My code is very messy and I know there are better ways to achieve this but I’m stumped as to how:
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
public GameObject explosionPrefabRed;
public GameObject explosionPrefabBlue;
public GameObject exp;
public static float bonus;
public int redCount;
public int blueCount;
public int chainBonus = 1;
// Use this for initialization
void Start ()
{
redWallCount = 1;
blueWallCount = 1;
}
// Update is called once per frame
void Update () {
if(redCount == 1)
chainBonus = 1;
if(redCount == 2)
chainBonus = 2;
if(redCount == 3)
chainBonus = 3;
if(redCount == 4)
chainBonus = 4;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Red")
{
redCount = redCount + 1;
blueCount = 0;
Vector3 explosionPos = transform.position;
exp = (GameObject)Instantiate(explosionPrefabRed, explosionPos, Quaternion.identity);
Destroy(exp, explosionLife);
other.transform.Translate(0,-4,0);//cheating way to fake death
bonus = 100 * Timing.time;
Scoring.score = Scoring.score + bonus * chainBonus;
Destroy(gameObject);
}
if (other.tag == "Blue")
{
redCount = 0;
blueCount = blueCount + 0;
Vector3 explosionPos = transform.position;
exp = (GameObject)Instantiate(explosionPrefabBlue, explosionPos, Quaternion.identity);
Destroy(exp, explosionLife);
bonus = 100 * Timing.time;
Scoring.score = Scoring.score + bonus;
Destroy(gameObject);
}
void OnGUI (){
GUI.Box(new Rect (Screen.width / 2 - 75,10,150,30), bonus.ToString("#") + " total Score");
GUI.Box(new Rect (Screen.width / 2 - 75,80,150,30), chainBonus + " chain");
GUI.Box(new Rect (Screen.width / 2 - 75,120,150,30), "red" + redCount);
}
}