Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Miaw666 · Jul 24, 2019 at 03:59 PM · destroytriggersdestroygameobjectstepsteps

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!!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Miaw666 · Jul 25, 2019 at 02:35 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

184 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My OnTriggerEnter destruction script won't trigger 1 Answer

Can't destroy gameobject inside coroutine? 0 Answers

Destroy GameObject after certain amount is reached? 1 Answer

Pass nothing inside OnTriggerEnter2D(Collider2D other) 0 Answers

Bullets not destroying enemies 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges