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
1
Question by Steven-1 · May 25, 2011 at 12:09 PM · animationmaterialanimated

Animated material

I want a billboard-lights material that has animating lights. So I made a scrolling-texture animation by animating the main texture offset.

Now the thing is, if I want something to have this material, I have to give that object an animation component and add that animation to it. And this also creates a new material for each object.

But I don't want it to make copys of the material each time it's used, I just want all these objects to use the same animated material without having to give it an animation component. (So what I really want is to store that animation in the material somehow)

Does anyone know how I can do something like this ?

Edit: I made a script to this instead:

 var mat:Material;
 
 function Update () 
 { 
     var offset:float = Mathf.Repeat (Time.time*2,1); 
     offset = Mathf.FloorToInt(offset*4)/4.0f; //clampen op 1/4
     
     Debug.Log("offset: "+offset);
     
     mat.mainTextureOffset.x = offset;
     mat.SetTextureOffset("_IlluminTex", new Vector2(offset,0));
 }

only problem is that I don't know what the Self-Illumination Texture is called. Anyone knows were to find it ?

EDIT2:

found it, it's "_Illum" If anyone wants to findout how something else is called in the build-in shaders, you can find the shaders here: http://unity3d.com/download_unity/builtin_shaders.zip

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 pyro · May 25, 2011 at 01:12 PM

If you are getting the material reference like this:

 Material mat;
 mat = renderer.material;

change it to this:

 Material mat:
 mat = renderer.sharedMaterial;

Using the first way will create a separate instance of the material. If you animate the sharedMaterial mainTextureOffset it will animate it for all objects with that material.

edit: since you edited your question with a script, in your script it would be:

 var gameObjectsMaterialToAnimate:GameObject;
 private var mat:Material;
 
 function Start()
 {
    mat = gameObjectsMaterialToAnimate.renderer.sharedMaterial;
 }
 
 function Update () 
 { 
     var offset:float = Mathf.Repeat (Time.time*2,1); 
     offset = Mathf.FloorToInt(offset*4)/4.0f; //clampen op 1/4
 
     Debug.Log("offset: "+offset);
 
     mat.mainTextureOffset.x = offset;
     mat.SetTextureOffset("_IlluminTex", new Vector2(offset,0));
 }
Comment
Add comment · Show 4 · 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
avatar image Steven-1 · May 25, 2011 at 01:52 PM 0
Share

I'm not getting the material refernce at all, there was no scripting involved. I animated the material by creating an animation and changing the the main texture offset in it.

I guess making a script that animates the material is a good enough way (as long as I only need 1 instance of the script).

avatar image Steven-1 · May 25, 2011 at 02:13 PM 0
Share

ok, this works:

var mat:$$anonymous$$aterial;

function Update () { var offset:float = $$anonymous$$athf.Repeat (Time.time*2,1); offset = $$anonymous$$athf.FloorToInt(offset*4)/4.0f; //clampen op 1/4

 Debug.Log("offset: "+offset);
 
 mat.mainTextureOffset.x = offset;
 mat.SetTextureOffset("_Illu$$anonymous$$Tex", new Vector2(offset,0));

}

only problem is that I don't know what the Self-Illu$$anonymous$$ation Texture is called. Anyone knows were to find it ?

avatar image pyro · May 25, 2011 at 03:50 PM 0
Share

that's close but you're still using the material ins$$anonymous$$d of the shared$$anonymous$$aterial, so it will instance

avatar image Steven-1 · May 31, 2011 at 12:27 PM 0
Share

uhm, no, I'm certain it uses the original material.

I'm not getting the material by renderer.shared$$anonymous$$aterial or renderer.material, I assign it in the scene (well, in a prefab with the script attached to be exact). So what you're saying is not possible.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

can i animate image sequence for material animation in unity ? 1 Answer

Changing Material in Animation 2 Answers

Bringing visibilty and material animation from Max to Unity 3 Answers

Can the animation editor create local rotational data? 3 Answers

Spin a texture in just any material -is it possible? 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