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 johnabraham · Dec 26, 2014 at 10:57 PM · arraymaterialruntimeobjectschanging

Changing the material at runtime for multiple objects in a single call

Hey guys!

I am newbie to unity please help me out form this, i am trying to make a unlimited 2d runner game and i have 5 environments to swap as per the user selection, on the play button event i am calling the "SetTheBackground()" method out of 9 bgs only one got effected. (may be the problem is in single frame it has been called). if i kept the folowwing code in update method it's working but fps issue.

we should not call in every frame. please help me out.

using UnityEngine; using System.Collections;

public class BackgroundManager : MonoBehaviour { public static BackgroundManager instance;

GameObject mgameObject; public Material[] bgmaterial;

void Awake() { mgameObject = this.gameObject; instance = this; }

public void SetTheBackground() { if (GameController.instance != null) { switch (GameController.instance._ThemeType) { case eTheme.Theme1: mgameObject.renderer.material= bgmaterial [0]; break; case eTheme.Theme2: mgameObject.renderer.material = bgmaterial [1]; break; case eTheme.Theme3: mgameObject.renderer.material = bgmaterial [2]; break; case eTheme.Theme4: mgameObject.renderer.material = bgmaterial [3]; break; case eTheme.Theme5: mgameObject.renderer.material = bgmaterial [4]; break; default: break;

      }
      
  } 
  else {
 
  }
 

} Thanks 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 abi-kr01 · Dec 27, 2014 at 08:03 AM 0
Share

plz format your code with alt text

its not readable

capture.png (5.9 kB)

0 Replies

· Add your reply
  • Sort: 

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

Changing material at runtime messes up with prefab materials [Solved] 1 Answer

Finding What Material Is On The Object Player Collided With. 1 Answer

Material attaching 0 Answers

Keeping track of array objects 2 Answers

objects in Array null when changing scenes 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