Unity Community |

I am translating some code from javascript to C# in a book im reading and ive across slight issue. When i translate this into C# it gives me the error
Error 1 The body of 'TileGenerator.MatchCheck()' cannot be an iterator block because 'void' is not an iterator interface type C:\Users\Phil\Documents\MatchGame\Assets\_scripts\ TileGenerator.cs 121 10 Assembly-CSharp-vs
So obviously i cant do this in C# how would i achieve the same affect?
Thanks, Phil
You kind of didn't paste the code, but I have a feeling from the error you're getting the coroutine is
Code:
void COROUTINE() { }
instead of
Code:
IEnumerator COROUTINE() { }
Here is my code
void MatchCheck()
{
if (tName1[0] == tName2[0])
{
canClick = false;
yield return new WaitForSeconds(2);
Destroy(matchOne);
Destroy(matchTwo);
canClick = true;
numberOfTiles = numberOfTiles - 2;
}
if (numberOfTiles == 0)
{
print("End Game");
}
else
{
canClick = false;
yield return new WaitForSeconds(2);
print("Rotate Back");
matchOne.transform.Rotate(new Vector3(0, -180f, 0));
matchTwo.transform.Rotate(new Vector3(0, -180f, 0));
canClick = true;
}
matchOne = null;
matchTwo = null;
}
maybe like this?Code:
[COLOR="red"]IEnumerator [/COLOR]MatchCheck() { ...
Programmer and junior artist
www.gamedesign.ro (an attempt to create a repository of gamedev resources)
My site www.gamingo.ro (romanian only)
Facebook group for romanian Unity3D users
Code:
IEnumerator MatchCheck() { if (tName1[0] == tName2[0]) { canClick = false; canClick = true; numberOfTiles = numberOfTiles - 2; } if (numberOfTiles == 0) { } else { canClick = false; canClick = true; } matchOne = null; matchTwo = null; }
thanks all that seemed to work!
Hi ployer, i´m trying to do the same as you with the same book, i cannot get my C# to work. This is my code
Code:
{ public int numberOfTiles = 16; GameObject matchOne; string tileName1; string[] tName1; GameObject matchTwo; string tileName2; string[] tName2; bool canClick = true; { }; // Use this for initialization { for (int i = 0; i<numberOfTiles; i++) { } } { if (canClick == true) { if (!matchOne) { revealCardOne (); } else { revealCardTwo (); } } } } } void revealCardOne () { if (matchOne == null) { } else { tName1 = tileName1.Split ("_" [0]); } } IEnumerator revealCardTwo () { if (tileName1 != tileName2) { if (matchTwo == null) { } else { tName2 = tileName2.Split ("_" [0]); } if (tName1 [0] == tName2 [0]) { canClick = false; canClick = true; numberOfTiles = numberOfTiles - 2; if (numberOfTiles == 0) { } } else { canClick = false; canClick = true; } matchOne = null; matchTwo = null; while (tileName1 != tileName2) { } } } }
it seems ok, but i cant get the yield to work correctly, i would appreciate your help, THANKS![]()
WaitForSeconds does nothing by itself. You need the yield return new like the original poster.
Available for consulting:
http://forum.unity3d.com/threads/960...Personal-Tutor
http://www.unityprogrammer.com
Just released The Farming Game: Software Edition, a remake of a popular board game. Check it out at the link below!
http://thefarminggame.net/?ref=Pride
For tutorials on how to use Unity go to my website at:
http://www.unity-tutorials.com
hi, i corrected my code, it´s a match game, i need that when two of the pieces do not match to wait a certain amount of time for the player to wait and see the other piece that doesnt match, but i cant get it to worki´m a begginer, i would really appreciate some help, thanks. Sorry for my english, it´s not my first language
Code:
using UnityEngine; using System.Collections; { public int numberOfTiles = 16; GameObject matchOne; string tileName1; string[] tName1; GameObject matchTwo; string tileName2; string[] tName2; bool canClick = true; { }; // Use this for initialization { for (int i = 0; i<numberOfTiles; i++) { } } { if (canClick == true) { if (!matchOne) { revealCardOne (); } else { revealCardTwo (); MatchCheck (); } } } } } void revealCardOne () { if (matchOne == null) { } else { tName1 = tileName1.Split ("_" [0]); } } void revealCardTwo () { if (tileName1 != tileName2) { if (matchTwo == null) { } else { tName2 = tileName2.Split ("_" [0]); } } } void MatchCheck () { if (tName1 [0] == tName2 [0]) { canClick = false; canClick = true; numberOfTiles = numberOfTiles - 2; if (numberOfTiles == 0) { } } else { canClick = false; canClick = true; } matchOne = null; matchTwo = null; if (tileName1 != tileName2) { } } IEnumerator initPos (float waitTime) { } }
Last edited by masterofyngwie; 05-14-2012 at 07:27 PM.
Here it is the project
http://www.mediafire.com/?5ubq3dmcm79akjl