i want to be able to change the level of motion blur based on a variable within the character’s movement script. however, the motion blur script does not inherit from monobehaviour, and i can’t get it to do so, so i can’t access the variable i need. here’s the code i’m trying to use right now, which gives me error CS1721: MotionBlur': Classes cannot have multiple base classes (ImageEffectBase’ and `UnityEngine.MonoBehaviour’)
using UnityEngine;
// This class implements simple ghosting type Motion Blur.
// If Extra Blur is selected, the scene will allways be a little blurred,
// as it is scaled to a smaller resolution.
// The effect works by accumulating the previous frames in an accumulation
// texture.
[AddComponentMenu("Image Effects/Motion Blur")]
public class MotionBlur : ImageEffectBase, MonoBehaviour
{
public float groundedAmount = 0.01f;
public float firstJumpAmount = 0.2f;
public float secondJumpAmount = 0.4f;
public float thirdJumpAmount = 0.8f;
public bool extraBlur = false;
private NormalCharacterMotor character;
private RenderTexture accumTexture;
void Start() {
character = GameObject.FindWithTag("Player").GetComponent(typeof(NormalCharacterMotor)) as NormalCharacterMotor;
}
protected new void OnDisable()
{
base.OnDisable();
DestroyImmediate(accumTexture);
}
// Called by camera to apply image effect
void OnRenderImage (RenderTexture source, RenderTexture destination)
{
// Create the accumulation texture
if (accumTexture == null || accumTexture.width != source.width || accumTexture.height != source.height)
{
DestroyImmediate(accumTexture);
accumTexture = new RenderTexture(source.width, source.height, 0);
accumTexture.hideFlags = HideFlags.HideAndDontSave;
ImageEffects.Blit( source, accumTexture );
}
// If Extra Blur is selected, downscale the texture to 4x4 smaller resolution.
if (extraBlur)
{
RenderTexture blurbuffer = RenderTexture.GetTemporary(source.width/4, source.height/4, 0);
ImageEffects.Blit(accumTexture, blurbuffer);
ImageEffects.Blit(blurbuffer,accumTexture);
RenderTexture.ReleaseTemporary(blurbuffer);
}
//determine the amount of blur based on which jump the character is doing
if (character.grounded) {
blurAmount = groundedAmount;
}
else if (character.jumpCount == 1) {
blurAmount = firstJumpAmount;
}
else if (character.jumpCount == 2) {
blurAmount = secondJumpAmount;
}
else if (character.jumpCount == 3) {
blurAmount = thirdJumpAmount;
}
// Clamp the motion blur variable, so it can never leave permanent trails in the image
blurAmount = Mathf.Clamp( blurAmount, 0.0f, 0.92f );
// Setup the texture and floating point values in the shader
material.SetTexture("_MainTex", accumTexture);
material.SetFloat("_AccumOrig", 1.0F-blurAmount);
// Render the image using the motion blur shader
ImageEffects.BlitWithMaterial (material, source, accumTexture);
ImageEffects.Blit(accumTexture, destination);
}
}
what other way should i try to do this?