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?
Answer by shawnatkidzpace · Jun 14, 2019 at 04:41 PM
I don't think you can have the Update nested in OnTriggerExit.
It works in the second example because update isn't nested.
Your answer
Follow this Question
Related Questions
Referencing instances of scripts based on the GameObject they are attached to. 0 Answers
how to unhide cursor when going to main menu? 1 Answer
Please Help Me: Assets/Scripts/PlayerControaller.cs(34,33): error CS8025: Parsing error 1 Answer
GetComponent("string") not working like GetComponent<>() ? 1 Answer