Hi I'm coming from a Java background. I cant find many resources on c# getters/setters in unity.
I have prefabs with the Block script attached to each. Each prefab is loaded into the MyBlocks[]
I just cant get/mod the values from the Block class in the class Player. So I'm really wondering how do c# setters and getters work in unity especially if I want to get/modify a private value from a class ?
public class Block : MonoBehaviour
{
[SerializeField]
private bool b = false;
public bool getB()
{
get{return b;}
}
}
public class Player : MonoBehaviour
{
public Block[] blockList;
public int size = 6;
public Block[] MyBlocks;
void start()
{
blockList = new Block[size];
for(int i = 0; i < size; i++)
{
int RandomNumber = Random.Range (0, MyBlocks.Length);
Instantiate(MyBlocks[RandomNumber],
MyBlocks[RandomNumber].transform.position ,
MyBlocks[RandomNumber].transform.rotation);
blockList[i] = MyBlocks[RandomNumber];
blockList[i].b = true;
Debug.Log("i: " + i + " " + blockList[i].b);
}
}
}
↧