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 /
avatar image
0
Question by ZBlaxland · Oct 17, 2016 at 07:24 AM · renderinginvisiblevisibleappearconvertc#

Converting C# to JS: rendering a mesh

So this is what I have:

GetComponent(MeshRenderer).enabled = false;

I got this from another question, but the rest of my script is Java and I was wondering if anyone knows a way to do this in Java rather than c#

basically, I have a box of matches, which I collect and after I collect it, what's SUPPOSED to happen is a note pops up on the screen when I get near the fireplace, telling me to use my matches. I then press "e" and voila, a fire appears...

Here is my script:

 #pragma strict
 
 var buttonInRange;
 var buttonActivated;
 var batterySound : AudioClip;
 var Transparent : Material;
 
 var Matches : GameObject;
 var Fire : GameObject;
 
 private var hasPlayed = false;
 
 function Start ()
 {
 //THIS IS WHERE I NEED HELP
 GetComponent(MeshRenderer).enabled = false;
 }
 
 
 function OnTriggerEnter (c : Collider)
 {
     buttonInRange = true;
 
 }
 
 
 function OnTriggerExit (c : Collider)
 {
     buttonInRange = false;
 
 }
 
     if (buttonInRange == true)
         {
 
         if (Matches == false)
 
             {
              
             GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50), "Use matches");
     
             }
         }
     }
 
 
 function Update ()
 {
     if (buttonInRange == true)
     {
         if (Input.GetKeyDown ("e"))
         {
             AudioSource.PlayClipAtPoint(batterySound, transform.position);
 //I ALSO NEED HELP HERE
             GetComponent(MeshRenderer).enabled = false;
 
             }
         }
         
     }
 
 

The problem I'm having is I can't make the fire start off invsible when the scene loads and become visible when I click "e" and have collected my matches.

If it helps, here is my match script:

 var buttonInRange;
 var buttonActivated;
 var batterySound : AudioClip;
 
 
 private var hasPlayed = false;
 
 function OnTriggerEnter (c : Collider)
 {
     buttonInRange = true;
 
 }
 function OnTriggerExit (c : Collider)
 {
     buttonInRange = false;
 
 }
 function OnGUI ()
 {
     if(buttonInRange == true)
     {
         GUI.Label (Rect (Screen.width/2-50, Screen.height/2-55, 120, 50), "Pick up matches");
     
     }
 
 }
 function Update ()
 {
     if (buttonInRange == true)
     {
         if (Input.GetKeyDown ("e"))
         {
             if(!hasPlayed)
             {
                 AudioSource.PlayClipAtPoint(batterySound, transform.position);
                 Destroy(gameObject);
                 hasPlayed = true;
             }
             }
         
         }
     
     }
 

Any help is much, much appreciated :D

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
1

Answer by Cherno · Oct 17, 2016 at 09:06 AM

You are accessing the MeshRenderer of the GameObject that the first script is on, which I assume is on the player character. What you want to do instead is access the MR of the Fire GameObject.

 function Start ()
  {
  Fire.GetComponent(MeshRenderer).enabled = false;
  }

..and so on.

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 ZBlaxland · Oct 17, 2016 at 12:26 PM 0
Share

So I just tried that, and it didn't work. I originally had the first script attached to the fire itself, but the tried it on the first person controller as per your suggestion. Unfortunately, neither worked...

Thanks for trying though, If I work it out I'll let you know

avatar image Cherno ZBlaxland · Oct 17, 2016 at 02:44 PM 0
Share

I suggest doing some debugging. Are you sure that all the parts of your code are actually reached when they should? Insert Debug.Log lines to find out and print results to the console.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Only render part of object inside a circle 2 Answers

How do I make one object appear when I mouse over another object? 1 Answer

Rendering with cubes/planes/matrices 2 Answers

Mouse over make object Visible 2 Answers

[javascript] detect when object is seen by camera, Renderer.isVisible not working 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