I’m making a race game and want to count score when a car is entering a gate. It must counts by adding 1 , but when I enter the gate it counts by adding 3. Also I want to make the game restarting when the car hit a collider and showing a text, but it doesn’t detect a collision. Here is my code.
using UnityEngine;
using System.Collections;
public class BodyColliderScript : MonoBehaviour {
Rigidbody attachedRigidbody;
int intLevel;
public GuiManager guiManager;
void Start()
{
intLevel = 0;
guiManager.levelLbl.text = string.Format("Level : {0}", intLevel.ToString());
attachedRigidbody = GetComponent<Rigidbody>();
}
void OnTriggerEnter(Collider col)
{
if(col.tag=="Gate")
{
intLevel += 1;
guiManager.levelLbl.text = string.Format("Level : {0}", intLevel.ToString());
}
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Road")
{
Debug.Log("Collision");
guiManager.ShowDeadText();
}
}
}