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 ComicGirl · Nov 28, 2017 at 09:26 PM · gameobjectobjectif-statementssetactiverenderer.enabled

The best methods for changing objects within a scene?

Hello, I've been looking into how to replace a GameObject with another GameObject. Allow me to explain: I have a SpringTree GameObject and a WinterTree GameObject. I already have a script that changes the season by using a String Variable currentSeason.
Basically, I want my objects to change their appearance based on what season it is. If it is Spring, use spring objects, etc. I have tried several different methods, such as using the SetActive method, but it has not worked. Is there any other way to accomplish what I am looking for?

Here was my last attempt that was based off another post I found. The script references another script that holds the value of the currentSeason.
Any help is greatly appreciated!

 public GameObject sceneController;
 private SeasonController seasonControllerScript;

 public GameObject springObject;
 public GameObject winterObject;
 // Use this for initialization
 void Start () {
     seasonControllerScript = sceneController.GetComponent<SeasonController>();
     if (seasonControllerScript.currentSeason == "Spring")
     {
         springObject.SetActive(true);
     }
     else if (seasonControllerScript.currentSeason == "Winter")
     {
         winterObject.SetActive(true);
     }

 }
 
 // Update is called once per frame
 void Update () {
     if (seasonControllerScript.currentSeason == "Spring")
     {
         springObject.SetActive(true);
         winterObject.SetActive(false);
     }
     else if (seasonControllerScript.currentSeason == "Winter")
     {
         winterObject.SetActive(true);
         springObject.SetActive(false);
     }

 }
Comment
Add comment · Show 2
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 lPVDl · Nov 28, 2017 at 10:42 PM 0
Share

I assume you do not need to replace trees with other trees for simulating seasons, y'd better create smooth material transition from spring to winter for bark and leaves.

avatar image MarkR22 · Nov 29, 2017 at 01:27 AM 0
Share

Are the spring and winter objects both in the scene or are you dragging in their prefabs from your project folder? If they're only prefabs and not in your hierarchy then SetActive will not do anything.

1 Reply

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

Answer by ComicGirl · Nov 29, 2017 at 02:27 AM

Thanks for all the replies! IPVDI was correct. Instead of using two different objects, I instead created the two different materials that represent the seasons, then created the script below that changes the materials based on the season. Thanks again for all the help, I appreciate the help with the direction! Script tested and works!

   public GameObject sceneController;
   private SeasonController seasonControllerScript;

 public Material springMaterial;
 public Material winterMaterial;
 // Use this for initialization
 void Start () {
     seasonControllerScript = sceneController.GetComponent<SeasonController>();
     if (seasonControllerScript.currentSeason == "Spring")
     {
         GetComponent<Renderer>().material = springMaterial;
     }
     else if (seasonControllerScript.currentSeason == "Winter")
     {
         GetComponent<Renderer>().material = winterMaterial;
     }

 }
 
 // Update is called once per frame
 void Update () {
     if (seasonControllerScript.currentSeason == "Spring")
     {

         GetComponent<Renderer>().material = springMaterial;
     }
     else if (seasonControllerScript.currentSeason == "Winter")
     {
         GetComponent<Renderer>().material = winterMaterial;

     }

 }
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

107 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

Related Questions

game object set active on trigger enter? 3 Answers

Need help with C# code. both gameObject and col.gameObject are getting destroyed. here is the code. 2 Answers

How to swap gameObjects on the press of a button? 1 Answer

activate GameObject dont work 1 Answer

Setting Without Altering Object Scale and Collider Scale 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