Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Objects INVISIBLE until I pass thru TRIGGER... HOW? I have scripts, but not doing it

Discussion in 'Scripting' started by ARRCOMM1, Nov 22, 2013.

  1. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    FIRST OFF ...... How do I get a Photo up here??? want to show my settings and script.
    I went down page to "Manage Attachments" and did not show any way to bring in .jpg picture.

    ALSO....Isn't there a way to show the code in a box up here, not as plain text style??
     
  2. Landern

    Landern

    Joined:
    Dec 21, 2008
    Posts:
    354
    There is a sticky post here: http://forum.unity3d.com/threads/143875-Using-code-tags-properly that explains how to use the code tags to format your code.

    As for the images, the "From Computer" tab seems to be missing the okay/cancel button. Try using imgur.com and upload there, use the "From URL" tab and paste the imgur link in there.
     
  3. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    937
    when replying to this thread, click the "Go advanced" button. This is the same text editor as when starting a new thread (almost). There are small icons to attach links, images, video's and code blocks (the code block is the # icon).
     
  4. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    Ok I see the "Go Advanced" when I press the Reply arrow under somebody's response. Did that.
    Now for Photo... $Invisibility.jpg

    notice I have the mesh boxes checked, but only for me too see the item while taking photo. When I get back in game build mode, I uncheck the Mesh boxes and the Object "step" is Invisible.
    But , during RUN mode, when I pass into the Trigger Zone for the Object, the Object (step) does not appear.
     
  5. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    $Inspector Settings.jpg $Steps.jpg

    Code (csharp):
    1. #pragma strict
    2.  
    3. function Start () {
    4.  
    5. }
    6.  
    7. var myMeshRenderer:MeshRenderer;
    8.  
    9. var RenderMesh:boolean = true;
    10. // gives toggle box on the object containing the mesh
    11.  
    12. function Update () {
    13.  
    14.  if(RenderMesh)
    15.   {
    16.   myMeshRenderer.enabled = true;
    17.   }
    18.  
    19.  
    20.   if(!RenderMesh)
    21.   {
    22.   myMeshRenderer.enabled = false;
    23.   }
    24.  
    25. }
     
  6. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    The Large outer box around step is, of course, the Trigger and the smaller box is the Collider to keep player from falling thru.
    The idea is to step on the 1st step and the 2nd appears. Jump to it and the 3rd appears, etc., etc.
     
  7. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    OK Been looking at code. I need a Collider code that tells the Mesh Render to go to TRUE if the Player comes in contact with the Trigger Zone.

    Am I on the right track???
    I do not want to stick with JS. Would like to make these things C#. So would like comments with codes in C#.
     
  8. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public MeshRenderer;
    5. public class Invisibility : MonoBehaviour {
    6.        
    7.     void OnTriggerEnter(Collider col){
    8.      if (col.gameObject.tag == "Player"){
    9.         }
    10.     GetComponent(MeshRenderer).enabled = true;
    11.     }  
    12.        
    13. }
    This did not work

    4:20 Parsing error

    I tried putting in "public MeshRenderer;" above the Behavior class, but that came up error Have a RED Line under it.
    I thought I could declare a variable without having to note a value.
     
  9. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Invisibility : MonoBehaviour {
    5.     public Rigidbody SteppingStone9;
    6.    
    7.     void OnTriggerEnter(Collider col){
    8.      if (col.gameObject.tag == "Player"){
    9.         Rigidbody Step = Instantiate(SteppingStone9, transform.position, transform.rotation) as Rigidbody;
    10.     }  
    11.        
    12. }
    13. }
    No ERRORS, but shouldn't I have a few boxes somewhere to fill in for the Position and Rotation I want???

    This STEP should appear near the ground attached to the CLIFF WALL near the Antelope in this scene
    $StepsScene.jpg
     
  10. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    Got it this works perfectly.........

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class StepInvisibility : MonoBehaviour {
    5.     void Start(){
    6.         Transform step = transform.Find("Step");
    7.             step.gameObject.SetActive(false);
    8.     }
    9.     void OnTriggerEnter(Collider col){
    10.      if (col.gameObject.tag == "Player"){
    11.         Transform step = transform.Find("Step");
    12.             step.gameObject.SetActive(true);
    13.  
    14.        }
    15.     }
    16.     /*  
    17.      Make an EMPTY creation and place a Collider around it and
    18.       designate it as a TRIGGER  Assign this script to the Empty
    19.      The gameObject is a model of an fbx model designated as a step
    20.      Make the Step a "Child" of the Empty object
    21.      When your level(game) starts, the Step is NOT there. Is not Active.
    22.      Once the Player makes contact with the Trigger around the Empty,
    23.       the Step appears
    24.      and you can step on it now. (Is Active now)
    25.       This can be done to ANY OBJECTS in GAME
    26.  */
    27. }
     
  11. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    Solved
     
  12. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Glad you got it solved. btw... to get the meshrenderer use: GetComponent<MeshRenderer>() not GetComponent(MeshRenderer). The difference is:

    If you just disable the meshrenderer, your object will be invisible but Update and FixedUpdate will still be executed on scripts attached to your object. If you use SetActive(false), the object will also be invisible... your triggers will still work, but your Update and FixedUpdate methods will not fire. Just something to keep in mind.. if you still need your object to update while it's invisible disable the meshrenderer, otherwise do what you did (using SetActive(false) to disable the object).
     
  13. ARRCOMM1

    ARRCOMM1

    Joined:
    Aug 19, 2013
    Posts:
    44
    Thank you, that may come in handy for something else I been thinking of. These steps need no Updates, but maybe the GetComponent<MeshRenderer>() will work for another object.

    This code will be like :


    using UnityEngine;

    using System.Collections;

    public MeshRenderer;

    public class Invisibility : MonoBehaviour ;


    void OnTriggerEnter(Collider col){


    if (col.gameObject.tag == "Player"){

    }


    GetComponent<MeshRenderer>() enabled = true;

    }
    }


    Is that correct??