How to Start/Stop Scripted Animation using a Trigger?

This is a really simple issue. So, when the player enters the trigger box of a platform, the platform starts rotating. And when the player exits the trigger box of the platform, the platform stops moving. The platform’s rotation is controlled by a few lines in the script. Take a look at the script below that is a component of the platform.

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

public class PlatformAttach : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            void Update()
            {
                transform.Rotate (new Vector3(0,Time.deltaTime*37,0));
            }
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            void Update()
            {
                transform.Rotate (new Vector3(0,Time.deltaTime*0,0));
            }
        }
    }
}

I know that the part of the script that rotates the platform works because I’ve tested it as it’s own script like this:

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

public class CameraRotator : MonoBehaviour
{
    void Update()
    {
        transform.Rotate (new Vector3(0,Time.deltaTime*37,0));
    }
}

But for some reason when I copy and paste this into the other script so that the trigger will start and stop the rotation, it doesn’t work. Does anyone know what to do?

I don’t think you can have the Update nested in OnTriggerExit.

It works in the second example because update isn’t nested.