Hi, on the pillar shown on the image below there are two box colliders. The top collider is a trigger placed on the top of the platform. It checks if the players lands on the platform and increases the score.
But the problem is that the lower collider, which isn’t a trigger, also increments the score if the player hits that non trigger collider. And I’m not sure why. This is the code and the image of the platform:
void OnTriggerEnter (Collider target)
{
if (target.tag == "Platform") {
if (didJump) {
didJump = false;
anim.SetBool ("Jump", didJump);
//Play landing sounds after jumping
audioSource.clip = landingListAU [UnityEngine.Random.Range (0, landingListAU.Length)];
audioSource.Play ();
//Instantiate the dust particles when landing after a jump
dustObject = Instantiate (dustPuff, this.transform.position, this.transform.rotation) as GameObject;
dustParticle = dustObject.GetComponent<ParticleSystem> ();
dustParticle.transform.Rotate (-90, 0, 0);
isGrounded = true;
// Increment score and instantiate platform. Also check if last platform was allready landed on
if (ScoreManager.instance != null && GameManager.instance != null) {
//Debug.Log ("Entered " + target + ", last platform was " + lastPlatformJumpedOn);
if (target != lastPlatformJumpedOn) {
lastPlatformJumpedOn = target;
ScoreManager.instance.IncrementScore ();
ScoreManager.instance.HighScore ();
GameManager.instance.CreateNewPlatformAndLerp (target.transform.position.x);
}
}
//reseting the y position for the player after jumping, sometimes the y position changes after a jump when landing on a platform.
transform.rotation = Quaternion.Euler(transform.rotation.x, 90, transform.rotation.z);
Debug.Log("Rotation for the player is now: " + transform.rotation);
}
}
if (target.tag == "FirstPlatform") {
if (didJump) {
didJump = false;
anim.SetBool ("Jump", didJump);
isGrounded = true;
}
}
if (target.tag == "Dead") {
if (GameOverManager.instance != null) {
GameOverManager.instance.GameOverShowpanel ();
}
//find gameobject to destroy just before the sore menu comes up after death
Destroy (cloudSpawner);
clouds = GameObject.FindGameObjectsWithTag("cloud");
foreach (GameObject cloud in clouds)
GameObject.Destroy(cloud);
platforms = GameObject.FindGameObjectsWithTag("Platform");
foreach (GameObject platform in platforms)
GameObject.Destroy(platform);
firstPlatforms = GameObject.FindGameObjectsWithTag("FirstPlatform");
foreach (GameObject firstPlatform in firstPlatforms)
GameObject.Destroy(firstPlatform);
Destroy (gameObject);
}
}