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 MerlinsMaster · Mar 30, 2017 at 05:38 AM · transparencyalphaunlit transparent

Changing the alpha of an Unlit/Transparent shader

Hey guys,

I'm working on a top-down 2D space sim, and I'm currently working on the graphic element that conveys motion when the spaceship is moving.

What I have is a quad, which moves with the ship, with a material on it that moves in the opposite direction that the ship is moving.

The quad follows the ship because of the following script:

 public class cs_GridFollow : MonoBehaviour {
 
     // define the grid's position on the Y-axis
     public float Ypos = -1.0f;
 
     // define player position for grid to follow
     public Transform player;
     
     void Update()
     {
         // grid follows player position
         transform.position = player.position + new Vector3(0, Ypos, 0);
     }
 }

The texture on the quad moves in the opposite direction of the ship because of the this script:

 public class cs_ScrollUV : MonoBehaviour {
 
     // This is the dimension of the quad divided by 20, the number of times
     // the texture is tiled across the material
     public float UVscaleFactor;
 
     private MeshRenderer mr;
     private Material mat;
     private Vector2 offset;
 
     void Start()
     {
         // Calls the MeshRenderer component of this game object
         mr = GetComponent<MeshRenderer>();
 
         // Creates an instance for this game object's material
         mat = mr.material;
 
         // Creates the Vector2 instance that will tell the UVs which way to go
         offset = mat.mainTextureOffset;
     }
 
     void Update()
     {
         // Defines the X and Y components of the Vector2
         offset.x = transform.position.x / UVscaleFactor;
         offset.y = transform.position.z / UVscaleFactor;
 
         // The material's UVs are offset by the Vector2 "offset"        
         mat.mainTextureOffset = offset;
     }
 }

I want to map the opacity of this graphic to the ship's speed, so that it is only visible when the ship is moving, and the faster the ship moves, the higher the opacity of the starfield texture flying by.

I wrote the following script to attempt to accomplish this:

 public class cs_VisibilityWithSpeed : MonoBehaviour 
 {
     public float opacity;
 
     private MeshRenderer mr;
     private Material mat;
 
     void Start () 
     {
         mr = GetComponent<MeshRenderer>();      // Calls the MeshRenderer component of this game object
         mat = mr.material;                      // Creates an instance for this game object's material
     }
     
     void Update () 
     {
         mat.color = new Color(1f, 1f, 1f, opacity);
         // NOTE: I haven't yet added code to link the opacity to the ship's motion yet.  
         // I'm still trying to get the texture to even recognize the opacity variable.
     }
 }

The problem I'm havng is that because of the type of shader I'm using(Unlit/Transparent), which is necessary for it to have transparency between the stars, there is apparently no control of the overall color, where the alpha setting is. And if I were to use a sprite, there would be no controls for the tiling and offset, which I need. So what can I do? There must be a solution. So many games have this type of effect.

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 Peakz · Mar 30, 2017 at 11:57 AM 1
Share

So are you basically looking for a fade animation between black and transparent which simulates the movement of the ship? If so this tutorial might help you: https://www.youtube.com/watch?v=2XNP6Qf2gDU I know it isn't in the same context as your idea, but the same concept applies.

avatar image MerlinsMaster Peakz · Mar 30, 2017 at 07:43 PM 0
Share

No, not exactly. The tutorial you linked has him animating the alpha, which is what I'm trying to do, but like I mentioned before, I'm not able to access the alpha with the shader type I'm using.

I currently have an image that has transparency in it. What I'm trying to do is make it completely transparent when it is not moving, but I don't want to disable it, I would like it to fade.

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

65 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

Related Questions

An Outline like the Editor does in game, with transparency 1 Answer

Does the Particle Animator work with transparent shaders? 1 Answer

Different transparency on same texture? 1 Answer

Texture transparency not working as expected 3 Answers

transparent RGBA PNG textures worked in 4.6, how can I get them working in Unity5? 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