Skip to main content
deleted 298 characters in body
Source Link
public Material []materialSequence;
new public Renderer renderer;

float playerExitTime = float.NegativeInfinity;
int state = 0;

bool PlayerStays = false;

void Awake()
{
    renderer = gameObject.GetComponent<MeshRenderer>();
}

void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        // Add a little tolerance, so rapid vibration at the edge of collision
        // doesn't advance the state. We need to leave for some time then return.
        if (Time.time - playerExitTime > 0.1f)
            AdvanceState();
        
    }
}

void OnCollisionStay(Collision collision)
{
    if (PlayerStays)
    {
        StartCoroutine(FallThenDestroy(10f5f, 3f9f));
        PlayerStays = false;
    }

    if (state == 1)
    {
        StartCoroutine(PlayerCheckStayStatus(1.5f));
    }
}

void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        playerExitTime = Time.time;
    }
}

void AdvanceState()
{
    // If we're already falling, ignore further state changes.
    if (state == materialSequence.Length)
        return;

    renderer.sharedMaterial = materialSequence[state];
    state++;

    if (state == materialSequence.Length)
        StartCoroutine(FallThenDestroy(10f, 3f));
}

// This lets us animate out the fall before the destruction takes place.
IEnumerator FallThenDestroy(float distance, float duration)
{
    PlayerStays = false;
    yield return new WaitForSeconds(0.5f);
    for (float t = 0; t < duration; t += Time.deltaTime)
    {
        // Fall some distance.
        transform.Translate(0, -distance * Time.deltaTime / duration, 0, Space.World);
        // Yield control to the engine to run for a frame, then resume here.
        yield return null;
    }

    // Destroy ourselves once the fall is over.
    Destroy(gameObject);
}

IEnumerator PlayerCheckStayStatus(float time)
{
    yield return new WaitForSeconds(time);
    PlayerStays = true;
    Debug.Log(PlayerStays);
}

Edited code like this, it works nice but i need to ask when i stay on one of the cubes after 1.5f seconds itcube falls but It falls very fast, i think duration from the FallThenDestroy multipliesmy character teleports to nearest cube around instead of falling with if (state == materialSequence.Length) StartCoroutine(FallThenDestroy(10f, 3f)); Because that if statement becames true too it. How can i fix it?

  1. How to fix that problem?
  2. When cube falls down, character teleports to the nearest cube instead of falling down with it. Need to fix it too :/
public Material []materialSequence;
new public Renderer renderer;

float playerExitTime = float.NegativeInfinity;
int state = 0;

bool PlayerStays = false;

void Awake()
{
    renderer = gameObject.GetComponent<MeshRenderer>();
}

void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        // Add a little tolerance, so rapid vibration at the edge of collision
        // doesn't advance the state. We need to leave for some time then return.
        if (Time.time - playerExitTime > 0.1f)
            AdvanceState();
        
    }
}

void OnCollisionStay(Collision collision)
{
    if (PlayerStays)
    {
        StartCoroutine(FallThenDestroy(10f, 3f));
    }

    if (state == 1)
    {
        StartCoroutine(PlayerCheckStayStatus(1.5f));
    }
}

void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        playerExitTime = Time.time;
    }
}

void AdvanceState()
{
    // If we're already falling, ignore further state changes.
    if (state == materialSequence.Length)
        return;

    renderer.sharedMaterial = materialSequence[state];
    state++;

    if (state == materialSequence.Length)
        StartCoroutine(FallThenDestroy(10f, 3f));
}

// This lets us animate out the fall before the destruction takes place.
IEnumerator FallThenDestroy(float distance, float duration)
{
    PlayerStays = false;
    yield return new WaitForSeconds(0.5f);
    for (float t = 0; t < duration; t += Time.deltaTime)
    {
        // Fall some distance.
        transform.Translate(0, -distance * Time.deltaTime / duration, 0, Space.World);
        // Yield control to the engine to run for a frame, then resume here.
        yield return null;
    }

    // Destroy ourselves once the fall is over.
    Destroy(gameObject);
}

IEnumerator PlayerCheckStayStatus(float time)
{
    yield return new WaitForSeconds(time);
    PlayerStays = true;
    Debug.Log(PlayerStays);
}

Edited code like this, it works nice but i need to ask when i stay on one of the cubes after 1.5f seconds it falls but It falls very fast, i think duration from the FallThenDestroy multiplies with if (state == materialSequence.Length) StartCoroutine(FallThenDestroy(10f, 3f)); Because that if statement becames true too.

  1. How to fix that problem?
  2. When cube falls down, character teleports to the nearest cube instead of falling down with it. Need to fix it too :/
public Material []materialSequence;
new public Renderer renderer;

float playerExitTime = float.NegativeInfinity;
int state = 0;

bool PlayerStays = false;

void Awake()
{
    renderer = gameObject.GetComponent<MeshRenderer>();
}

void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        // Add a little tolerance, so rapid vibration at the edge of collision
        // doesn't advance the state. We need to leave for some time then return.
        if (Time.time - playerExitTime > 0.1f)
            AdvanceState();
        
    }
}

void OnCollisionStay(Collision collision)
{
    if (PlayerStays)
    {
        StartCoroutine(FallThenDestroy(5f, 9f));
        PlayerStays = false;
    }

    if (state == 1)
    {
        StartCoroutine(PlayerCheckStayStatus(1.5f));
    }
}

void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        playerExitTime = Time.time;
    }
}

void AdvanceState()
{
    // If we're already falling, ignore further state changes.
    if (state == materialSequence.Length)
        return;

    renderer.sharedMaterial = materialSequence[state];
    state++;

    if (state == materialSequence.Length)
        StartCoroutine(FallThenDestroy(10f, 3f));
}

// This lets us animate out the fall before the destruction takes place.
IEnumerator FallThenDestroy(float distance, float duration)
{
    PlayerStays = false;
    yield return new WaitForSeconds(0.5f);
    for (float t = 0; t < duration; t += Time.deltaTime)
    {
        // Fall some distance.
        transform.Translate(0, -distance * Time.deltaTime / duration, 0, Space.World);
        // Yield control to the engine to run for a frame, then resume here.
        yield return null;
    }

    // Destroy ourselves once the fall is over.
    Destroy(gameObject);
}

IEnumerator PlayerCheckStayStatus(float time)
{
    yield return new WaitForSeconds(time);
    PlayerStays = true;
    Debug.Log(PlayerStays);
}

Edited code like this, it works nice but i need to ask when cube falls, my character teleports to nearest cube around instead of falling with it. How can i fix it?

added 391 characters in body
Source Link
public Material []materialSequence;
new public Renderer renderer;

float playerExitTime = float.NegativeInfinity;
int state = 0;

bool PlayerStays = false;

void Awake()
{
    renderer = gameObject.GetComponent<MeshRenderer>();
}

void OnCollisionStayOnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        // Add a little tolerance, so rapid vibration at the edge of collision
        // doesn't advance the state. We need to leave for some time then return.
        if (Time.time - playerExitTime > 0.1f)
            AdvanceState();
        
    }
}

void OnCollisionExitOnCollisionStay(Collision collision)
{
    if (collision.gameObject.CompareTagPlayerStays)
    {
        StartCoroutine("Player"FallThenDestroy(10f, 3f));
    {}

    if (state == 1)
 playerExitTime = Time {
        StartCoroutine(PlayerCheckStayStatus(1.time;5f));
    }
}

void AdvanceStateOnCollisionExit(Collision collision)
{
    if (PlayerStayscollision.gameObject.CompareTag("Player"))
    {
        StartCoroutine(FallThenDestroy(10f,playerExitTime 3f));= Time.time;
    }
   }

void AdvanceState()
{
    // If we're already falling, ignore further state changes.
    if (state == materialSequence.Length)
        return;

    renderer.sharedMaterial = materialSequence[state];
    state++;

    if (state == materialSequence.Length)
        StartCoroutine(FallThenDestroy(10f, 3f));
    if (state == 1)
    {
        StartCoroutine(PlayerCheckStayStatus(1.5f));
    }
}

// This lets us animate out the fall before the destruction takes place.
IEnumerator FallThenDestroy(float distance, float duration)
{
    PlayerStays = false;
    yield return new WaitForSeconds(0.5f);
    for (float t = 0; t < duration; t += Time.deltaTime)
    {
        // Fall some distance.
        transform.Translate(0, -distance * Time.deltaTime / duration, 0, Space.World);
        // Yield control to the engine to run for a frame, then resume here.
        yield return null;
    }

    // Destroy ourselves once the fall is over.
    Destroy(gameObject);
}

IEnumerator PlayerCheckStayStatus(float time)
{
    yield return new WaitForSeconds(time);
    PlayerStays = true;
    Debug.Log(PlayerStays);
}

I've tried somethingEdited code like thatthis, it works nice but i need to ask when i step intostay on one of the cubes after 1.5f seconds it falls but It falls very fast, it's material changes to the last materiali think duration from the array and falls downFallThenDestroy multiplies with if (state == materialSequence.Length) StartCoroutine(FallThenDestroy(10f, 3f)); Because that if statement becames true too. How to fix it?

  1. How to fix that problem?
  2. When cube falls down, character teleports to the nearest cube instead of falling down with it. Need to fix it too :/
public Material []materialSequence;
new public Renderer renderer;

float playerExitTime = float.NegativeInfinity;
int state = 0;

bool PlayerStays = false;

void Awake()
{
    renderer = gameObject.GetComponent<MeshRenderer>();
}

void OnCollisionStay(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        // Add a little tolerance, so rapid vibration at the edge of collision
        // doesn't advance the state. We need to leave for some time then return.
        if (Time.time - playerExitTime > 0.1f)
            AdvanceState();
        
    }
}

void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        playerExitTime = Time.time;
    }
}

void AdvanceState()
{
    if (PlayerStays)
    {
        StartCoroutine(FallThenDestroy(10f, 3f));
    }
    
    // If we're already falling, ignore further state changes.
    if (state == materialSequence.Length)
        return;

    renderer.sharedMaterial = materialSequence[state];
    state++;

    if (state == materialSequence.Length)
        StartCoroutine(FallThenDestroy(10f, 3f));
    if (state == 1)
    {
        StartCoroutine(PlayerCheckStayStatus(1.5f));
    }
}

// This lets us animate out the fall before the destruction takes place.
IEnumerator FallThenDestroy(float distance, float duration)
{
    PlayerStays = false;
    yield return new WaitForSeconds(0.5f);
    for (float t = 0; t < duration; t += Time.deltaTime)
    {
        // Fall some distance.
        transform.Translate(0, -distance * Time.deltaTime / duration, 0, Space.World);
        // Yield control to the engine to run for a frame, then resume here.
        yield return null;
    }

    // Destroy ourselves once the fall is over.
    Destroy(gameObject);
}

IEnumerator PlayerCheckStayStatus(float time)
{
    yield return new WaitForSeconds(time);
    PlayerStays = true;
    Debug.Log(PlayerStays);
}

I've tried something like that, but when i step into one of the cubes, it's material changes to the last material from the array and falls down. How to fix it?

public Material []materialSequence;
new public Renderer renderer;

float playerExitTime = float.NegativeInfinity;
int state = 0;

bool PlayerStays = false;

void Awake()
{
    renderer = gameObject.GetComponent<MeshRenderer>();
}

void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        // Add a little tolerance, so rapid vibration at the edge of collision
        // doesn't advance the state. We need to leave for some time then return.
        if (Time.time - playerExitTime > 0.1f)
            AdvanceState();
        
    }
}

void OnCollisionStay(Collision collision)
{
    if (PlayerStays)
    {
        StartCoroutine(FallThenDestroy(10f, 3f));
    }

    if (state == 1)
    {
        StartCoroutine(PlayerCheckStayStatus(1.5f));
    }
}

void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        playerExitTime = Time.time;
    }
}

void AdvanceState()
{
    // If we're already falling, ignore further state changes.
    if (state == materialSequence.Length)
        return;

    renderer.sharedMaterial = materialSequence[state];
    state++;

    if (state == materialSequence.Length)
        StartCoroutine(FallThenDestroy(10f, 3f));
}

// This lets us animate out the fall before the destruction takes place.
IEnumerator FallThenDestroy(float distance, float duration)
{
    PlayerStays = false;
    yield return new WaitForSeconds(0.5f);
    for (float t = 0; t < duration; t += Time.deltaTime)
    {
        // Fall some distance.
        transform.Translate(0, -distance * Time.deltaTime / duration, 0, Space.World);
        // Yield control to the engine to run for a frame, then resume here.
        yield return null;
    }

    // Destroy ourselves once the fall is over.
    Destroy(gameObject);
}

IEnumerator PlayerCheckStayStatus(float time)
{
    yield return new WaitForSeconds(time);
    PlayerStays = true;
    Debug.Log(PlayerStays);
}

Edited code like this, it works nice but i need to ask when i stay on one of the cubes after 1.5f seconds it falls but It falls very fast, i think duration from the FallThenDestroy multiplies with if (state == materialSequence.Length) StartCoroutine(FallThenDestroy(10f, 3f)); Because that if statement becames true too.

  1. How to fix that problem?
  2. When cube falls down, character teleports to the nearest cube instead of falling down with it. Need to fix it too :/
Source Link

public Material []materialSequence;
new public Renderer renderer;

float playerExitTime = float.NegativeInfinity;
int state = 0;

bool PlayerStays = false;

void Awake()
{
    renderer = gameObject.GetComponent<MeshRenderer>();
}

void OnCollisionStay(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        // Add a little tolerance, so rapid vibration at the edge of collision
        // doesn't advance the state. We need to leave for some time then return.
        if (Time.time - playerExitTime > 0.1f)
            AdvanceState();
        
    }
}

void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        playerExitTime = Time.time;
    }
}

void AdvanceState()
{
    if (PlayerStays)
    {
        StartCoroutine(FallThenDestroy(10f, 3f));
    }
    
    // If we're already falling, ignore further state changes.
    if (state == materialSequence.Length)
        return;

    renderer.sharedMaterial = materialSequence[state];
    state++;

    if (state == materialSequence.Length)
        StartCoroutine(FallThenDestroy(10f, 3f));
    if (state == 1)
    {
        StartCoroutine(PlayerCheckStayStatus(1.5f));
    }
}

// This lets us animate out the fall before the destruction takes place.
IEnumerator FallThenDestroy(float distance, float duration)
{
    PlayerStays = false;
    yield return new WaitForSeconds(0.5f);
    for (float t = 0; t < duration; t += Time.deltaTime)
    {
        // Fall some distance.
        transform.Translate(0, -distance * Time.deltaTime / duration, 0, Space.World);
        // Yield control to the engine to run for a frame, then resume here.
        yield return null;
    }

    // Destroy ourselves once the fall is over.
    Destroy(gameObject);
}

IEnumerator PlayerCheckStayStatus(float time)
{
    yield return new WaitForSeconds(time);
    PlayerStays = true;
    Debug.Log(PlayerStays);
}

I've tried something like that, but when i step into one of the cubes, it's material changes to the last material from the array and falls down. How to fix it?