Create your properties etc in a class (mine is called TileProps) and attach it to your prefab:
using UnityEngine;
using System.Collections;
public class TileProps : MonoBehaviour {
public int tileX = 0;
public int tileZ = 0;
public float posX = 0.0f;
public float posZ = 0.0f;
}
Then you can access the properties in code like this:
// 'tile' is the object
tileProps = (TileProps)tile.GetComponent( "TileProps" );
tileProps.posX = 3.0f; // etc
Well, if you don’t want to use GetComponent (ScriptName), you may do a variable theScriptName : ScriptName, drag and drop the component ScriptName of the prefab into the variable theScriptName field.
public class Player
{
// Define a private variable
private int experience;
// Define a public property with getter and/or setter
public int Experience
{
get
{
return experience;
}
set
{
experience = value;
}
}
}
The benefit of this is that it is encapsulated, and also gives you the power to make it read/write only by omitting either get or set.
You could also add more code to either function, if you wanted to modify the value in some way.