I’ve tried setting the Rigidbody velocity to a Vector3.zero (on the TriggerExit function) , yet the platform keeps going up into the infinite no matter what i write to lock it down, i wanted to lock the platform in place once it has reached a certain point in the Y axis - so that it could only fall down once the player no longer pressed the button to keep the platform up. As you can see i’m a complete beginner - i hope i’ve been clear enough. Thanks, any help is appreciated - if i can be more clear let me know.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ElevatorButton : MonoBehaviour
{
//public GameObject Elevator;
public GameObject elevator;
private Rigidbody rb;
public float speed;
float stop;
//bool isActivated = false;
private void Awake()
{
rb = elevator.GetComponent<Rigidbody>();
}
void OnTriggerStay(Collider col)
{
if (col.gameObject.CompareTag("Player"))
{
rb.useGravity = false;
rb.velocity = transform.up * speed;
Debug.Log("ahahah");
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.CompareTag("Player"))
{
rb.useGravity = true;
}
}
}