- Home /
AssemblyCSharp.ColorAnimator.color.get': cannot explicitly call operator or accessor
how can i fix this issue ? thanks in advance :
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins;
using System.Reflection;
using UnityEngine;
namespace AssemblyCSharp
{
public class ColorAnimator
{
private PropertyInfo prop;
private object obj;
private Tween tween;
private Color color
{
get
{
return (Color)this.prop.GetValue(this.obj, null);
}
set
{
this.prop.SetValue(this.obj, value, null);
}
}
public ColorAnimator(object obj, string colorPropName = "color")
{
this.obj = obj;
this.prop = obj.GetType().GetProperty(colorPropName);
if (this.prop != null)
{
return;
}
}
public void Animate(Color endColor, float duration)
{
if (this.prop != null)
{
this.StopTween();
this.tween = DOTween.To(new DOGetter<Color> (this.get_color), delegate(Color x)
{
this.color = x;
}, endColor, duration);
this.tween.OnComplete(new TweenCallback(this.ClearTween));
}
}
private void StopTween()
{
if (this.tween != null)
{
this.tween.Kill(false);
}
}
private void ClearTween()
{
if (this.tween != null)
{
this.tween.Kill(false);
this.tween = null;
}
}
}
}
Answer by Bunny83 · May 20, 2018 at 04:24 AM
I'm pretty sure the error comes from this:
this.get_color
Even though the internal name of the getter method is "get_color" you can not directly access this method like that. The only way would be through reflection. However since you declared your color property as private it seems the only usage of that property is to pass it to the tween library. So it would be way easier to declare two methods instead of a property.
Though if you want to keep the property you can try this:
new DOGetter<Color> (()=>this.color)
Though it's just another layer in between. This lambda as well as your setter delegate are just additional methods. So i would recommend to get rid of the property and replace it with two seperate methods:
private Color get_color()
{
return (Color)this.prop.GetValue(this.obj, null);
}
private void set_color(Color col)
{
this.prop.SetValue(this.obj, col, null);
}
I don't know that tween library so I can't give you the exact usage in your case.
thank you so much, that help, just another error was appeared :
AssemblyCSharp.ColorAnimator' does not contain a definition for
color' and no extension method color' of type
AssemblyCSharp.ColorAnimator' could be found. Are you missing an assembly reference?
this.color = x;
thanks again
As i said i don't have that tween library so i don't know how the exact signature of "To" looks like. However it should work like this:
this.tween = DOTween.To(new DOGetter<Color> (this.get_color), this.set_color, endColor, duration);
Your answer
Follow this Question
Related Questions
My rigidbody2d is passing through the side of a collider2d but it's working on the top 0 Answers
Simple way to save large files 0 Answers
Why is this error happening 1 Answer
Scripting Backend for APK in Unity 5 1 Answer
Hide Input always false 0 Answers