Hi all - in my game a moving sphere can hit static cubes on the plane - the right cubes turn green and win you 1 life, the wrong cubes turns red and cost you 1 life.
Cubes have “Cube” as tag.
to change the color i use:
using UnityEngine;
using System.Collections;
public class REDCHANGECOLOR : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision Col) {
if(tag == "Cube") renderer.material.color = Color.red;
}
}
and to count lives I use:
using UnityEngine;
using System.Collections;
public class LivesCounter : MonoBehaviour {
int lives = 3;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision Col) {
if(tag == "Cube") lives--;
else lives++;
GUIText guiLives = GameObject.Find ("guiLives").GetComponent();
guiLives.text = "Lives: " + lives;
}
}
Cubes change colot all-right but the game does not work properly - in particular:
a) the counter does not count negatives, it counts +1 with any cube it touches
b) unexpectedly - once hit, some cubes determine a count of -2 points...
I am quite stuck on this, all help and/or suggestions would be very welcome - especially as I am new at this.
Thank you!
Alma