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 /
This question was closed Feb 13, 2021 at 09:07 PM by ThiccSnowM4N.
avatar image
0
Question by ThiccSnowM4N · Feb 09, 2021 at 10:01 PM · scripting problemlerppost processing

How can i change post processing at run time using if statements

basically im creating a bullet time game where time slows down if the player is aiming. I also want the vignette intensity to increase from the value it is to the higher value i want it to be and then when the player stops aiming to change from the higher back to the lower. I also want this effect to be smooth, so probably using Mathf.lerp. Ive followed a few tutorials on how to change postprocessing at run time and can do that but somehow when i use if statemtents it messes everything up.

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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Pokedlg3 · Feb 10, 2021 at 02:06 AM

You would have to get the Post Process Volume and try to take the vignette and put it as an output for the Vignette variable and then be able to change its properties there. Don't forget to put the UnityEngine.Rendering.PostProcessing library.

Something like this would work:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Rendering.PostProcessing;

 public class YourScript : MonoBehaviour
 {
     [Range(0,1)]
     public float lerpTime;
     Vignette vignette = null;
     float max = 1f;
     float min = 0f;
     bool aiming;

     void Start() 
     {
         PostProcessVolume volume = GetComponent<PostProcessVolume>();
         volume.profile.TryGetSettings(out vignette);
     }

    void Update() 
    {
        if(vignette !=null && aiming == true){
            vignette.intensity.value = Mathf.Lerp(vignette.intensity.value, max,Time.deltaTime * lerpTime);
         }
         else if(vignette !=null && aiming == false)
         {
             vignette.intensity.value = Mathf.Lerp(vignette.intensity.value, min,Time.deltaTime * lerpTime);
         }
    }

}

When running it may generate a Null Reference error, but don't worry, it will work.

Comment
Add comment · Show 1 · 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 ThiccSnowM4N · Feb 10, 2021 at 05:55 PM 0
Share

Thank you!!! This worked very well with very little tweaking needed. Only thing i really NEEDED to change was to used unscaledDeltaTime as through my slow motion function I changed deltaTime . Here is my updated version of the script for anybody who stumbles across this wanting to accomplish the exact same thing. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.PostProcessing; public class Slow$$anonymous$$oPostProcess : $$anonymous$$onoBehaviour { public PostProcessVolume volume; private Vignette vignette = null; private float intensity; public float lerpTime; float max = .6f; float $$anonymous$$ = .4f; bool ai$$anonymous$$g = false; void Start() { volume.profile.TryGetSettings(out vignette); } void Update() { if (Input.Get$$anonymous$$ouseButtonDown(1)) { ai$$anonymous$$g = true; }else if (Input.Get$$anonymous$$ouseButtonUp(1)) { ai$$anonymous$$g = false; } if (vignette != null && ai$$anonymous$$g == true) { vignette.intensity.value = $$anonymous$$athf.Lerp(vignette.intensity.value, max, Time.unscaledDeltaTime * lerpTime); } else if (vignette != null && ai$$anonymous$$g == false) { vignette.intensity.value = $$anonymous$$athf.Lerp(vignette.intensity.value, $$anonymous$$, Time.unscaledDeltaTime * lerpTime); } } }

avatar image
0

Answer by ThiccSnowM4N · Feb 10, 2021 at 06:01 PM

for whatever reason my code would not format correctly in my response to the above person so here it is. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.PostProcessing;

 public class SlowMoPostProcess : MonoBehaviour
 {
     public PostProcessVolume volume;
 
     private Vignette vignette = null;
 
     private float intensity;
 
 
     
     public float lerpTime;
     float max = .6f;
     float min = .4f;
     bool aiming = false;
     void Start()
     {
         volume.profile.TryGetSettings(out vignette);
     }
     void Update()
     {
         if (Input.GetMouseButtonDown(1))
         {
             aiming = true;
         }else if (Input.GetMouseButtonUp(1))
         {
             aiming = false;
         }
         if (vignette != null && aiming == true)
         {
             vignette.intensity.value = Mathf.Lerp(vignette.intensity.value, max, Time.unscaledDeltaTime * lerpTime);
         }
         else if (vignette != null && aiming == false)
         {
             vignette.intensity.value = Mathf.Lerp(vignette.intensity.value, min, Time.unscaledDeltaTime * lerpTime);
         }
     }
 }
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

Follow this Question

Answers Answers and Comments

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

(Problem) Turning postprocessing on and off 0 Answers

Modify values on VolumeProfile URP. 1 Answer

,How to blend Color Curves through script - Color Curve Interpolation 0 Answers

Rotate quaternion 90 degrees when clicked? 0 Answers

How do you change PP effects at runtime? 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