Hi, I am trying to “rebuild” some of there more famous concepts of other games / people to learn how things work. At the moment, I try to build something like this:
Platform at Start of Game: Color Grey
Player 1 jumps on it → Turns Blue
Player 2 jumps on it → Turns Pink
For Player 1, whenever the Platform is pink, the Collider is ignored and visa versa.
It works for the most part, however there is one issue.
If the Platform already is blue or pink and the player of the opposite color jumps on it, the platform does change it’s color and also ignores the collider after. As example:
Platform is blue. Pink player jumps on it.
What SHOULD happen is that the platform is completely ignored, as it’s blue.
What DOES happen is that it changes to pink and more or less at the same time, it is ignored.
That of course makes the platform non available for the blue player as well, but also for the pink player as the visual color is pink, but it seems to get processed as blue.
So the question is, how can I make the pink player ignore a blue platform completely?
I tried changing the collider of the player, but then again, the jump detection doesn’t work…here is my code, it’s probably bad but well I tried to not just copy everything
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Platform : MonoBehaviour
{
private Renderer rend;
public Color blue;
public Color pink;
void Start()
{
rend = GetComponent<Renderer>();
}
public void OnCollisionEnter2D(Collision2D collision)
{
if (rend.material.color == pink && collision.gameObject.tag == "playerblue")
{
Physics2D.IgnoreLayerCollision(9, 10);
}
if (collision.gameObject.tag == "playerblue")
{
rend.material.color = blue;
}
if (rend.material.color == blue && collision.gameObject.tag == "playerpink")
{
Physics2D.IgnoreLayerCollision(9, 10);
}
if (collision.gameObject.tag == "playerpink")
{
rend.material.color = pink;
}
}
}