A step vanishes when you step off it?
I'm tryng to make a stop that vanishes (destoys) when you step off it. When you stop on it nothing happens, but when you step off it it disappears so the player won't be able to reuse it.
I made a script for the step to be times for 3 sec after u stop on it, but it didn't work without the step being effected by gravity or being "isTrigger".
I need the step to float in empty-space and when the player steps on it nothing happens, but when he/she stops off it it vanshies.
Thanks!!
Answer by Vega4Life · Jul 24, 2019 at 06:51 PM
Here is something that works. I have a player object with a rigidbody and collider. I have steps with rigidbodies that use no gravity and are kinematic and a collider.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Simple player mover that just moves it forward so i can move down steps
public class PlayerController : MonoBehaviour
{
Rigidbody rb;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
if (Input.GetKey(KeyCode.RightArrow))
{
rb.MovePosition(transform.position + transform.forward * Time.deltaTime * 1f);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This is placed on your steps
public class StepController : MonoBehaviour
{
bool isPlayerOn;
private void OnCollisionEnter(Collision collision)
{
// Is it a player - using markup (this makes sure other things doesn't hit the step and turn it off
PlayerController player = collision.gameObject.GetComponent<PlayerController>();
if (player)
{
isPlayerOn = true;
}
}
private void OnCollisionExit(Collision collision)
{
if (isPlayerOn)
{
gameObject.SetActive(false);
isPlayerOn = false;
}
}
}
Worked fine for me, hopefully it gives you some idea of doing it.
Haha I'm having a hard time getting it to work, but that's only because Idk how to, the code is super good. Thanks a lot I was looking for a script like this but didn't find any. Thank you!!
Your answer
Follow this Question
Related Questions
My OnTriggerEnter destruction script won't trigger 1 Answer
Destroying GameObject after amount of triggers 2 Answers
reset destroyed collider after game restart 1 Answer
Generated AssetBundle only works when created within same Unity Project? 0 Answers
Create new transform when other transfrm is destroyes 1 Answer