How to make a platform fall down after stepping on it?

There are a few platforms. After the player moves from one platform to another the first one is supposed to fall. The platform that the player is on is supposed to remain still until the player moves to another one. The idea is that the character/player can’t return to a platform he was already on. What I tried: #pragma strict

function OnCollisionEnter(Char){ GetComponent.().useGravity = true; }

I put this script on the platforms but they start to fall as soon as I step on them.

You could try using on collision exit… Even have a timer so if they leave the platform for like two frames it won’t fall.

Add a script to the block with int timer bool isonblock,active;

Then on collision enter set active to true, isonblock to true

Then on collision exit isonblock to false

And update if active&&!isonblock then timer ++

If timer>15 then set gravity true

You can use OnCollisionExit().

Something like this

void OnCollisionExit()
	{
		GetComponent<Rigidbody> ().useGravity = true;
	}

Or you can even put a timer or so if you want them to fall in a timely manner.
you can code it something this way

bool playerEntered = false;
	float timeStood = 0f;


	void OnCollisionEnter()
	{
		playerEntered = true;
	}
	void Update () {
	
		if (playerEntered) {
			timeStood += Time.deltaTime;
			if(timeStood > 3) // Maximum a player can stand on the platform is 3 I put
				GetComponent<Rigidbody> ().useGravity = true;
		}
	}

As your current script works but at the wrong time, simply changing OnCollisionEnter to OnCollisionExit should do the job.

Okay guys I with the help of a friend was able to figure out the script. Here it is:

using UnityEngine; using System.Collections;

public class PlatformFall : MonoBehaviour { public Rigidbody platform; private bool hasPlayerExited; float timer = 0f;

void Start ()
{
platform = GetComponent();
platform.isKinematic = true;
platform.useGravity = false;
}

void OnCollisionEnter()
{
hasPlayerExited = false;
}

void OnCollisionExit()
{
hasPlayerExited = true;
}

void Update ()
{
if (hasPlayerExited == true) {
timer += Time.deltaTime;
if(timer > 0.5) {
platform.isKinematic = false;
platform.useGravity = true;
}
}
}
}