Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 gopics · Nov 10, 2014 at 03:17 PM · gameobjectmeshhidemeshfilterswapping

how to hide the mesh of the gameobject ?

Hai to all....i want to change the mesh of the game object....now i got small idea about mesh swapping....theese are my codings..

 public class meshchanging
 {
 public Gameobject initialobject;
 public Gameobject swapobject;
  msh initialmesh;
 mesh swapmesh;
 Gameobject theTarget;
 
 void start(){
 theTarget=initialObject;
 initialmesh=initialobject.getcomponent<meshfilter>().mesh;
 swapmsh=swapobject.getcomponent<meshfilter>().mesh;
 }
 void update(){
 theTarget.getcomponenet<meshfilter>().mesh=swapmesh;
 }
 }




now whats my problem was i cannot hide my initial game object......what my objective is when the new mesh is shown the old one want to hide.....help me in scripting...... and give some another coding to change the mesh while the game running ...without mesh swapping.......Thank in advance...

Comment
Add comment · Show 1
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 MrSoad · Nov 10, 2014 at 03:22 PM 0
Share

Just have both mesh objects on your object from the start. Then turn off the mesh render for the one you don't want and turn it on for the one that you do. See this part of the docs for the script :

http://docs.unity3d.com/ScriptReference/Renderer-enabled.html

1 Reply

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

Answer by CHPedersen · Nov 10, 2014 at 03:28 PM

You've actually kind of almost got it, but there are several things that seem strange here. The strange part is that your script actually has overall correct structure, but the errors indicate there are some very basic things about programming you would benefit from studying.

First of all: Spelling. C# is not a case insensitive language, and it has zero tolerance for spelling mistakes. Correct spelling is of paramount importance! You must not spell variables and method names in lower case.

I took the liberty to correct the naming mistakes and also apply normal C# naming conventions. The script then looks like this:

 using UnityEngine;
 using System.Collections;
 
 public class MeshChanging : MonoBehaviour
 {
     public GameObject InitialObject;
     public GameObject SwapObject;
     private Mesh initialmesh;
     private Mesh swapmesh;
     public GameObject theTarget;
 
     void Start()
     {
         theTarget = InitialObject;
         initialmesh = InitialObject.GetComponent<MeshFilter>().mesh;
         swapmesh = SwapObject.GetComponent<MeshFilter>().mesh;
     }
 
     void Update()
     {
         theTarget.GetComponent<MeshFilter>().mesh = swapmesh;
     }
 }

Second of all: Scripts must derive from MonoBehaviour. Your own classes (classes that do not derive from MonoBehaviour) cannot be attached to GameObjects, and therefore do not get their Update and Start methods called. I added the required inheritance to the class declaration.

Third of all: Consider carefully what your script actually does, then think about whether that is what you want. Remember that Update gets called every single frame. Do you want to immediately swap the mesh on the first frame, and then eternally set it to the same mesh every frame thereafter? My guess is: probably not. ;)

This is enough answer to your question for now. Try to edit it further, play with what it does, then ask another question when or if you find it doesn't quite do what you imagined.

Best of luck!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Converting a number of runtime-created prefab GameObject cube's for export 0 Answers

How to assign Icosphere to meshFilter with script? 1 Answer

Mesh dissapearing from Resources 0 Answers

Using MeshFilter.mesh with static ground plane makes object turn into a plane. 0 Answers

NullReferenceException on assigning vector3 to mesh.vertices - no effect on assignment? 1 Answer


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