C
C#16mo ago
羅馬繞道

❔ Compiler cannot infer lambda return type

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Cysharp.Threading.Tasks;

public class Title : MonoBehaviour
{
void Start() {
StartCoroutine(ShowTitles());
}

IEnumerator ShowTitles() {
string[] words = {"The", "White", "Christmas", "welcomes", "you!"};
foreach (var pack in words.Select((word) => {
var obj = GameObject.Find(word);
var render = obj.GetComponent<MeshRenderer>();
Material mat = render.materials[0];

var colour = mat.GetColor("_Color");
float H, S, V;
Color.RGBToHSV(colour, out H, out S, out V);
mat.SetColor("_Color", Color.HSVToRGB(H, S, 1));

return new {mat, H, S, V};
})) {
int x = 10;
for (int i=0; i < x; i++) {
yield return new WaitForSeconds(0.1f);

pack.mat.SetColor("_Color", Color.HSVToRGB(pack.H, pack.S, pack.V / (float)x));
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Cysharp.Threading.Tasks;

public class Title : MonoBehaviour
{
void Start() {
StartCoroutine(ShowTitles());
}

IEnumerator ShowTitles() {
string[] words = {"The", "White", "Christmas", "welcomes", "you!"};
foreach (var pack in words.Select((word) => {
var obj = GameObject.Find(word);
var render = obj.GetComponent<MeshRenderer>();
Material mat = render.materials[0];

var colour = mat.GetColor("_Color");
float H, S, V;
Color.RGBToHSV(colour, out H, out S, out V);
mat.SetColor("_Color", Color.HSVToRGB(H, S, 1));

return new {mat, H, S, V};
})) {
int x = 10;
for (int i=0; i < x; i++) {
yield return new WaitForSeconds(0.1f);

pack.mat.SetColor("_Color", Color.HSVToRGB(pack.H, pack.S, pack.V / (float)x));
}
}
}
}
\Avatar\Title.cs(25,20): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
\Avatar\Title.cs(25,20): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
5 Replies
Kouhai
Kouhai16mo ago
Looks like Select isn't linq's Select? I don't see System.Linq namespace
羅馬繞道
羅馬繞道OP16mo ago
Thank you. My code compiles now after importing the namespace.
jcotton42
jcotton4216mo ago
Why the hell are you using Select like that pepetense
羅馬繞道
羅馬繞道OP16mo ago
Code too many Rust I just get used to people reviewing my Rust code as "iter hell".
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server