Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 MeroDN · Oct 31, 2015 at 04:28 AM · 3dplatformerhiddencolission

How Can I make a plane only visible when steped on?

I have an invisible platform that I only want to be visible when the player is standing on it. I then want it to turn invisible again when the player steps off. I prefer C# and am developing a 3d game (you can tell, as the tittle mentions the "plane" object)

I have tried many scripts but: my coding skills < a baby's

Edit: It seems that the FPSController does not work with OnCollisionEnter?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MeroDN · Oct 31, 2015 at 06:18 PM

I decided to add a trigger colider to the pllanes and used this script I came up with: using UnityEngine; using System.Collections;

 public class See_if_touching : MonoBehaviour
 {
 
     private bool UnderPlayer = false;
 
     void OnTriggerEnter(Collider other)
     {
         if (other.tag == "Player")
         {
             UnderPlayer = true;
         }
     }
 
     void OnTriggerExit(Collider other)
     {
         if (other.tag == "Player")
         {
             UnderPlayer = false;
         }
     }
 
     void Update()
     {
         if (UnderPlayer)
         {
             GetComponent<MeshRenderer>().enabled = true;
         }
         else
         {
             GetComponent<MeshRenderer>().enabled = false;
         }
     }
 }
Comment
Add comment · 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
0

Answer by ElDo · Oct 31, 2015 at 09:06 AM

A script like this could do the trick (not tested):

 using UnityEngine;
 using System.Collections;
 
 public class InvisiblePlatform : MonoBehaviour {
  int _numOccupants=0;
  void OnCollisionEnter(Collision collision){
   _numOccupants++;
   foreach(Transform t in transform){
    t.GetComponent<Renderer>().enabled=true;
   }
  }
  void OnCollisionExit(Collision collsion){
   _numOccupants--;
   if(numOccupants==0){
    foreach(Transform t in transform){
     t.GetComponent<Renderer>().enabled=false;
    }
   }
  }
 }

attach this to the platform. As soon as something collides with it all renderers in all transform will be enabled and as soon as nothing's left on the platform it will be disabled again. It Counts the number of objects that enter the platform to make it back invisible as all have left it so it won't get invisble as still someone stays on it.

Comment
Add comment · Show 2 · 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 MeroDN · Oct 31, 2015 at 03:33 PM 0
Share

Does not seem to be working. sorry

avatar image Statement · Oct 31, 2015 at 03:39 PM 0
Share

try using GetComponentsInChildren<Renderer>() ins$$anonymous$$d (reference).

 using UnityEngine;
 
 public class InvisiblePlatform : $$anonymous$$onoBehaviour
 {
     int numOccupants = 0;
 
     public void Enter()
     {
         if (numOccupants++ == 0)
             ShowPlatform(true);
     }
 
     public void Exit()
     {
         if (--numOccupants == 0)
             ShowPlatform(false);
     }
 
     void Awake()
     {
         ShowPlatform(false);
     }
 
     void OnCollisionEnter()
     {
         Enter();
     }
 
     void OnCollisionExit()
     {
         Exit();
     }
 
     void ShowPlatform(bool show)
     {
         foreach (var renderer in GetComponentsInChildren<Renderer>())
             renderer.enabled = show;
     }
 }

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

34 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

Related Questions

Double Jump using character controller 0 Answers

Wall Jump with Jump Delay 0 Answers

How can I Wall Jump with a Delay 1 Answer

Struggling with bounce pad in platformer game. 1 Answer

How to hide and show level based on player/camera position? 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