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
1
Question by opporo · Jun 03, 2016 at 12:10 PM · meshrendererskinnedmeshrenderervisibilitymesh renderer

can't toggle mesh renderer visibility

Hi all, I've been trying to find a solution for this for almost 4 hours but still nothing. I have a character mesh which is made of multiple meshes (the hair, the shirt, the shorts). When the ChangeForm input is given, I need to turn off the shorts and shirt skinned Mesh Renderer. For some reason, I can turn it off but it won't turn on again. I also tried pacing the script in another gameobject, but still it doesn't work. using UnityEngine; using System.Collections;

 public class ToggleVisibility : MonoBehaviour
 {
 
     //VARS//
 
     private PlayerState _player;
     private InputManager _inputManager;
 
     public GameObject top;
     public GameObject shorts;
     private SkinnedMeshRenderer topMesh;
     private SkinnedMeshRenderer shortsMesh;
 
     public enum PlayerState
     {
         NormalForm,
         EtherealForm,
     }
 
     // Use this for initialization
     void Start()
     {
         _inputManager = FindObjectOfType<InputManager>();
         _inputManager.OnChangeForm += ChangeForm;
         _player = PlayerState.NormalForm;
         topMesh = top.GetComponent<SkinnedMeshRenderer>();
         shortsMesh = shorts.GetComponent<SkinnedMeshRenderer>();
     }
 
     private void ChangeForm()
     {
         switch (_player)
         {
             case PlayerState.NormalForm:
                 {
                     topMesh.enabled = false;
                     shortsMesh.enabled = false;
 
                     break;
                 }
             case PlayerState.EtherealForm:
                 {
 
                     topMesh.enabled = true;
                     shortsMesh.enabled = true;
                     Debug.Log("enabled mesh renderer");
 
                     break;
                 }
             default:
                 //if i'm here i'm dead so do nothing
                 break;
         }
 
     }
 
 }
 
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 opporo · Jun 08, 2016 at 04:59 PM

Ok, sometimes I'm not very smart! I just forgot to change the player state once the event is triggered.

using UnityEngine; using System.Collections;

public class ToggleVisibility : MonoBehaviour {

 //VARS//

 private playerState _myState;
 private InputManager _inputManager;

 private SkinnedMeshRenderer mesh;

 public enum playerState
 {
     normalForm,
     etherealForm,
 }

 // Use this for initialization
 void Start()
 {
     _inputManager = FindObjectOfType<InputManager>();
     _myState = playerState.normalForm;
     mesh = this.GetComponent<SkinnedMeshRenderer>();
     _inputManager.OnChangeForm += ChangeForm;
 }

 private void ChangeForm()
 {
     switch (_myState)
     {
         case playerState.normalForm:
             {
                 //hide meshes
                 mesh.enabled = false;
                 _myState = playerState.etherealForm;

                 break;
             }
         case playerState.etherealForm:
             {
                 //show meshes
                 mesh.enabled = true;
                 _myState = playerState.normalForm;

                 break;
             }
         default:
             //se sono qua sono morto quindi non faccio niente
             break;
     }

 }

}

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.

Follow this Question

Answers Answers and Comments

57 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

Related Questions

How can i apply a material to a prefab ? -1 Answers

Mesh Baker - maintaining interactivity of individual source objects 0 Answers

How can I access material of a mesh renderer without receiving and instance of it? 1 Answer

fbx Rigged Mesh has weird lightings 0 Answers

Why does skinned mesh renderer make the object looks more brigther than mesh renderer? 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