Integer is being added by 2 when the code says to do it by 1.
Ok, so I'm developing a 3D Platformer Game. And I have a integer that is being added by one every time you win. This it is being added in OnTriggerEnter method. For some reason it sometimes gets added by 2, instead of one.
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class WinScript : MonoBehaviour
{
void Start()
{
}
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
if (LevelButtonMethodHolder.StoryPlay)
{
Player.speedPower = 5f;
Player.CurrentLevel ++;
SceneManager.LoadScene(sceneName: "Menu");
}
if (!LevelButtonMethodHolder.StoryPlay)
{
Player.speedPower = 5f;
SceneManager.LoadScene(sceneName: "Menu");
}
}
}
If you need to see any other scripts then ask. Thank you for helping :D
There are most likely two objects entering the trigger (maybe a parent and a child)
private void OnTriggerEnter(Collider other)
{
Debug.Log(other.name + " has entered the trigger");
// ...
}
Oh your right! I have a game object under the player mesh, but the thing is that the object under the player doesn't have a collider.
Your answer
Follow this Question
Related Questions
Problem while using several tags in a OnTriggerEnter (Collider other) 0 Answers
Twine & Cradle,Using Cradle for Twine storytelling 0 Answers
The bool activates and deactivates but the script in the if statement doesn´t work 1 Answer
Why does my if statement skip the body even when the response is true? 1 Answer