﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FallingPlatform : MonoBehaviour {

    public float delay = 2.0f;

    public bool turnOnFall = false;

    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Player")
        {
            //print("hit by player");
            Invoke("DelayedFall", delay);
        }
    }

    void DelayedFall()
    {
        //print("delayed fall");
        gameObject.AddComponent<Rigidbody>();
        if (turnOnFall)
        {
            GetComponent<Rigidbody>().AddTorque(Random.Range(-100, 100), 0, Random.Range(-100, 100)); 
        }
    }
    
}
