Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 maw0041 · Nov 19, 2018 at 09:51 PM · prefabprefab-instancehideshowprefab changing at runtime

How to hide a character prefab

Explanation of what I'm doing: I currently have a Player object with many scripts associated with it, then I have a graphics object as a child of that (the other child of that is the camera), and then I have a playerModel that will have multiple prefab children with animator controller and animatorw script. The scrip triggers animations. I have a script that toggles the weapons wielded and displays them on the right side of the camera. That is what the player will see. But I want everyone else to see the player animations and the player holding the weapon. The reason I made multiple prefabs was because I wanted to player prefab to be unique to that specific weapon and be able to grab it. I know where to add the code to hide the player prefab and show the rest of them ( already know it works this way because I have selected hide in the inspector and ran it and it works just fine, I just want the CODE to trigger the hiding, not have to manually do it by me)

TL;DR how to hide my game object Player (1) > Graphics > playerModel > Model T pose 2 I want to hide Model T pose 2 in a script that is not necessarily attached to that specific object. I also want to show another variation of Model T Pose 2 once the other one is hidden. Please tell me how to access it to hide it from any script.

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 tinylord202 · Dec 09, 2018 at 03:46 AM

There are three ways to do such.

  • public references

  • GameObject.Find()

  • public static

If you have an object that is not placed at run time I would suggest using the public reference to the model. This be set up like

 public GameObject model

From here just assign it to the empty box labeled "model" in the editor. GameObject.FInd is good if you instantiate the object that is finding the model. You would use it like

 GameObject model = GameObject.Find("Model T Pose 2")

A public static reference is a quicker way to find the model if you instantiated it, but it is a bit more complicated. First you would need a script on the model that simply said

 public class ModelReference : MonoBehavior {
 public static GameObject model;
 void Awake() {
 
      model = this.gameObject;
 
      }
 }

from here you would just do something like

 void getModel (){
 GameObject model = ModelReference.model;
 }

The public static method can only work if there is only one object with that script on it.

From here you would simply use model.setActive(false)

To change the model you could either change the mesh in the mesh filter or enable a new gameobject that is a sibling to model t pose 2.

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

122 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing the variable 'power' of ONE turret instead of ALL turrets 1 Answer

Prefabs instantiated at runtime disappear right after 0 Answers

Prefabs spawn with wrong values 0 Answers

Prefabs won't change? 1 Answer

How to change a your player look in once scene and then load it in another 2 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