hello I am writing a script from a book called Unity 4.x game develop by example : beginner guide book, but I checked all the code there is nothing wrong, but Unity doesn’t compile it.
here is my code
{#pragma strict
import System.Collections.Generic;
var cols : int = 4;
var rows : int = 4;
var totalCards : int = 16;
var matchesNeededToWin : int = totalCards * 0.5;
var matchesMade : int = 0;
var cardWH : int = 100;
var aCards : List.;
var aGrid : Card[,];
var aCardsFlipped : List.;
var playerCanClick : boolean;
var playerHasWon : boolean = false;
function Start () {
playerCanClick = true;
aCards = new List.<Card>(); // this Generic list is our deck of
aGrid = new Card[rows,cols]; // The rows and cols variables help us
aCardsFlipped = new List.<Card>(); // This list will store the two
BuildDeck();
for (var i:int = 0; i<rows; i++){
for (var j:int = 0; j<cols; j++){
aGrid[i,j] = new Card();
}
}
}
function OnGUI () {
GUILayout.BeginArea (Rect (0,0,Screen.width,Screen.height));
BuildGrid();
GUILayout.EndArea();
print("building grid!");
}
class Card extends System.Object
{
var isFaceUp : boolean = false;
var isMatched : boolean = false;
var img : String;
function Card(){
img = "robot";
}
}
function BuildGrid(){
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
for (var i:int=0; i<rows; i++)
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
for (var j:int=0; j<cols; j++)
{
var card : Card = aGrid[i,j];
if (GUILayout.Button (Resources.Load(card.img), GUILayout.Width(cardWH)))
{
Debug.Log(card.img);
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
function BuildDeck(){
var totalRobots : int = 4;
var card : Card;
for (var i:int=0; i<totalRobots; i++)
{
var aRobotParts : List.<String> = new List.<String>();
aRobotParts.Add("Head");
aRobotParts.Add("Arm");
aRobotParts.Add("Leg");
for (var j:int=0; j<2; j++)
{
var someNum : int = Random.Range(0, aRobotParts.Count);
var theMissingPart : String = aRobotParts[someNum];
aRobotParts.RemoveAt(someNum);
**card = new Card("robot" + (i+1) + "Missing" + theMissingPart);**
aCards.Add(card);
**card = new Card("robot" + (i+1) + theMissingPart);**
aCards.Add(card);
}
}
}
}
at the end, this error shows up
Assets/Scripts/GameScript.js(105,36): BCE0024: The type ‘Card’ does not have a visible constructor that matches the argument list ‘(String)’.
Assets/Scripts/GameScript.js(108,36): BCE0024: The type ‘Card’ does not have a visible constructor that matches the argument list ‘(String)’.
this error is for the lines that I made bold in the end.
thank you so much for you time