2016-12-22 2 views
1

私はsystem.actionのC#での理解に問題があります。 IEnumeratorがメソッド内の文字列を出力したいのですが、どうすれば実現できますか?私はこれで何かを見つけることができません。 Ikはsystem.actionでメソッドを渡すことができることを知っていますが、どのようにしてパラメータでメソッドを渡すことができますか、これを行う方法でさえあります。それを行う方法さえありますか?Unity 3d-system.action <string>これをIEnumeratorで動作させる方法は?

https://msdn.microsoft.com/en-us/library/018hxwa8(v=vs.110).aspx

using UnityEngine; 
using System.Collections; 

public class Test : MonoBehaviour { 

    void Start() 
    { 
     StartCoroutine(test2(test("Hello World"))); // << also an error here "cannot convert from void to System.Action<string>" 
    } 

    void test(string t) 
    { 
     Debug.Log(t); 
    } 

    IEnumerator test2 (System.Action<string> _method) 
    { 
     _method(); // << here is the error how can I fix the syntax 
     yield return null; 
    } 
} 

答えて

2

あなたtest()メソッドをラップし、test2()にパラメータを追加します。

StartCoroutine(test2( delegate(string s){ test(s); } , "hello world")); 

IEnumerator test2(System.Action<string> _method, string message) 
{ 
    _method(message); 
    yield return null; 
} 
+0

私は調整を1回行いました。 –

+0

@MikeOttink oh ya、wouldntはメソッドをラップする必要がありました、私はxDを考えていました – Lincoln

0

をこれは、ヘルプリンカーンのためのおかげで働きました。

using UnityEngine; 
using System.Collections; 

public class Test : MonoBehaviour { 

    void Start() 
    { 
     StartCoroutine(test2(test, "whoehoe")); 
    } 

    void test(string t) 
    { 
     Debug.Log(t); 
    } 

    IEnumerator test2(System.Action<string> _method, string _bla) 
    { 
     _method(_bla); 
     yield return null; 
    } 

} 
関連する問題