Quantcast
Channel: Questions in topic: "protection"
Viewing all articles
Browse latest Browse all 107

C# protection level problem

$
0
0
Hello everyone , I'm reading Unity 4.x Game Development by Example Beginner Guide and trying to make sample projects which are in this book. In this book , a lot of code is wrotten in JavaScript. So i want to make a little bit harder this so i'm trying to write codes in C#. In a project a have a problem about protection level problem. It's giving protection level error in BuildGrid function. I can't reach the class variable from kart.img. It says img is inaccessible due to its protection level. Can you help me about this ? So here is my code : using UnityEngine; using System.Collections; using System.Collections.Generic; public class GameScript : MonoBehaviour { // Use this for initialization public int kolon = 4; public int satir = 4; public int toplamKart = 16; public double kazanmaPuani; public int tamamlananMac = 0; public int kartW = 100; List kartlar; Card[,] aGrid; List donen; bool oynanabilir; bool kazandi=false; void Start () { kazanmaPuani = toplamKart * 0.5; oynanabilir = true; kartlar = new List(); aGrid = new Card[satir, kolon]; donen = new List(); for (int i = 0; i < satir; i++) { for (int j = 0; j < kolon; j++) { aGrid[i, j] = new Card(); } } } // Update is called once per frame void OnGUI () { GUILayout.BeginArea(new Rect(0, 0,Screen.width ,Screen.height)); BuildGrid(); GUILayout.EndArea(); print("building grid!"); } public class Card { bool acik = false; bool eslesik = false; string img; public Card() { img = "robot"; } } void BuildGrid() { GUILayout.BeginVertical(); for (int i = 0; i < satir; i++) { GUILayout.BeginHorizontal(); for (int j = 0; j < kolon; j++) { Card kart = new Card(); kart = aGrid[i, j]; if (GUILayout.Button(Resources.Load(kart.img), GUILayout.Width(kartW))) { Debug.Log(kart.img); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } }

Viewing all articles
Browse latest Browse all 107

Trending Articles