Error: The type `bool' cannot be used as type parameter `TEventArgs' in the generic type or method `System.EventHandler'. There is no boxing conversion from `bool' to `System.EventArgs'
So I had asked about how to achieve having a bool change to true if a float value increases and false when it decreases on stackoverflow and this was the response. I am new to unity so I don't fully understand everything in that code but I am getting an error.
if someone could explain the error, and maybe a possible fix it would be appreciated.
Error: The type bool' cannot be used as type parameter
TEventArgs' in the generic type or method System.EventHandler<TEventArgs>'. There is no boxing conversion from
bool' to `System.EventArgs'
Here's his code that I modified slightly, so that the value that is being checked is the X position of the player so that the bool can detect if you are moving right or left.
public class FloatIncreasing : EventArgs
{
public GameObject player;
void Awake()
{
_Value = player.transform.position.x;
}
private float _Value;
public float Value
{
get
{
return _Value;
}
set
{
ValueChangeEvent(this, _Value >= value);
_Value = value;
}
}
public Boolean HasIncreased { get; private set; }
public event EventHandler<Boolean> ValueChangeEvent; // Error Here
public FloatIncreasing()
{
this.ValueChangeEvent += OnValueChanged;
}
public virtual void OnValueChanged(object sender, Boolean value)
{
HasIncreased = value;
// You can add a more appropriate default behavior in here.
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612115020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
error CS0201 1 Answer
Unity 5 doesn't detect some positions in Vector3 0 Answers
The Built [exe] of my game won't go past Splash Screen 0 Answers
Visual Studio 2015 keeps crashing... 1 Answer
I have an error on a C# script @username 2 Answers