• 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 /
avatar image
0
Question by ARRCOMM1 · Nov 27, 2013 at 08:33 PM · invisible

How do I make this "step" appear when Triggered by Player ?

Here is one code I came up with and tried (not Working) No Errors, just can't see WHERE to assign the Location and Rotation values in the Inspector.....

 using UnityEngine;
 using System.Collections;
 
 public class Invisibility : MonoBehaviour {
     public Rigidbody SteppingStone9;
     
        void OnTriggerEnter(Collider col){
      if (col.gameObject.tag == "Player"){
         Rigidbody Step = Instantiate(SteppingStone9, transform.position, transform.rotation) as Rigidbody;
     }    
         
 }
 }


ALSO TRIED same code BUT use isVisible = True instead of the Instantiate system

I desire to stay in C# for this code.

Comment
Add comment · Show 2
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 Spinnernicholas · Nov 27, 2013 at 08:48 PM 0
Share

OnTriggerEnter only gets called it one of the collider is set as a trigger.

Is that the case?

avatar image ARRCOMM1 · Nov 27, 2013 at 09:42 PM 0
Share

Ah !! Should have included these for more details.

alt text

alt text

Step is a box collider An Empty IS the trigger Box zone $$anonymous$$esh Renderer NOT checked in the Step Inspector

invisiblestepinspector.jpg (72.7 kB)
invisiblestep.jpg (40.3 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Nov 27, 2013 at 11:13 PM

What's the idea? Instantiate an object in front of the player when he enters the trigger? If so, you should use col.transform.position as the base position, and possibly add an offset in order to find the target position - kind of:

 using UnityEngine;
 using System.Collections;
  
 public class Invisibility : MonoBehaviour {
     public Rigidbody SteppingStone9;
     // offset relative to player position:
     public Vector3 offset = new Vector3(0, -1, 1);
  
     void OnTriggerEnter(Collider col){
         if (col.gameObject.tag == "Player"){
             // calculate player position plus offset:
             Vector3 pos = col.transform.TransformPoint(offset);
             Rigidbody Step = Instantiate(SteppingStone9, pos, transform.rotation) as Rigidbody;
         }  
     }
 }

If you want to use the same rotation as the player, replace transform.rotation with col.transform.rotation.

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 ARRCOMM1 · Nov 28, 2013 at 04:09 AM 0
Share

$$anonymous$$y First idea is to step in a region and the invisible step appears. I was wanting the step just to be invisible and when I get into the Trigger area, it appears. (The $$anonymous$$esh renderer becomes TRUE) I step on it and when I do, I am also in the region of the next STEP. And so on. So the Steps appear as I step on the one before them.

Then I tried Instantiation, but not seeing where to put the Location of the step. But now I see I should make the Instantiation position to be a location point referencing the Players' current position. Yes, that makes sense. Thank you. It would be sort of like a Childs' location as compared to it's Parent Object location. You don't work with the Childs' World Location, you work with it based upon the Parent....

Looking at your help here I am beginning to understand. I am looking at my book from Will Goldstone entitled "Unity 3.x Game Development Essentials" along with your code and some other references. Thank you for the idea and the lead to the next step. No pun intended.

avatar image aldonaletto · Dec 01, 2013 at 01:49 PM 0
Share

Another possibility is to place the steps at their places and set them inactive in the Inspector, then activate each step as the player enters a trigger above it. This is a better solution when you want the steps to be at fixed positions. For this to work, the trigger must not be childed to the step, since deactivating an object deactivates all its children; childing the step to the trigger works fine with a script like this (attached to the trigger):

 void OnTriggerEnter(Collider col){
   if (col.CompareTag("Player")){
     Transform step = transform.Find("Step");
     step.gameObject.SetActive(true);
   }
 }

The hierarchy should be like this:

 Trigger // empty that has the trigger volume
   Step // step object, childed to the trigger
avatar image
0

Answer by ARRCOMM1 · Dec 02, 2013 at 09:17 PM

Ok, I looked at the SetActive explanation in the Scripting Reference and here is what it said....

GameObject.SetActive

void SetActive(bool value);

Description

Activates/Deactivates the GameObject.

Note that a GameObject may be inactive because a parent is not active. In that case, calling SetActive() will not activate it, but only set the local state of the GameObject, which can be checked using GameObject.activeSelf. This state will then be used once all parents are active.

See Also: GameObject.activeSelf, GameObject.activeInHierarchy.

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour {
     void Example() {
         gameObject.SetActive(false);
     }
 }

But I still see my steps. All of them; even though I assigned this script ( from you ) to the Empty Object, which is the trigger and the Step is the child.

So, after looking at the script, I see the SetActive is TRUE in your script, but I need it to be False before going True.

I rewrote the script to this...

 using UnityEngine;
 using System.Collections;
 
 public class StepInvisibility : MonoBehaviour {
     void Start(){
         Transform step = transform.Find("Step");
             step.gameObject.SetActive(false);
     }
        void OnTriggerEnter(Collider col){
      if (col.gameObject.tag == "Player"){
         Transform step = transform.Find("Step");
             step.gameObject.SetActive(true);
 
        }
     }
 }

IT WORKS GREAT !!!
OORAH
here are the pics

GAME START alt text

Triggered the STEPS alt text


stepsinvisible.jpg (22.5 kB)
stepsappeared.jpg (38.0 kB)
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Renderer on object disabled after level reload 1 Answer

How to make an object invisible 3 Answers

Why is my script-crafted mesh invisible in game-mode? (C#) 1 Answer

Lightmapping on a custom shader 0 Answers

Image disappear on runtime 2D 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