Hey guys,
I am still pretty new to Unity and coding and have been trying to solve this problem myself for a while but am stuck.
I have a 2d top down world map similar to old rpgs like dragon warrior, final fantasy,etc.
The problem I am having is entering and exiting the ship, I have a script on the ship itself and in the OnTriggerStay2D function I have it watch for a button press, when it is pressed it checks if the player is already on the ship. If he is not it disables the player and changes control to the ship and sets the camera to follow the ship.
If the player is on the ship it looks at the collider and checks for one named Grass1 (so it lets you off on land not water) and then enables the player and sets the position to that of the Grass1 tile.
The issue I am having is that when you try to enter the ship it will put you on then instantly move you off to one of the Grass1 tiles so both scenarios are being used. I sort of understand why that is happening but can not find a solution to the problem.
If I change the code to use a different button for each, x on controller to enter ship, o on controller to exit ship then it will work fine but I want both of them to work when pressing Fire1.
Any suggestions?
Here is the code I have right now.
void OnTriggerStay2D(Collider2D col)
{
if (Input.GetButtonDown ("Fire1"))
{
if (!IsPlayerOnShip)
{
if (col.name == "Player")
{
IsPlayerOnShip = true;
Player.SetActive (false);
}
}
}
if (Input.GetButtonDown ("Fire2"))
{
if (IsPlayerOnShip)
{
if (col.name == "Grass1")
{
IsPlayerOnShip = false;
Player.transform.position = col.transform.position;
Player.SetActive (true);
}
}
}
}