- Home /
change property an object when another change
Hi, I create a class that have few properties for example "color,height and ...". then I attached that class into tow objects by name "A" and "B", now how can i change value of a property from "B" when property in "A" change?
Answer by Arkuni · Jul 30, 2013 at 10:20 PM
If you want the property to be synced across all GameObjects which has your MonoBehavior class attached, then you could give the class a static field and just have the property reference that field.
Answer by parsamiga · Jul 31, 2013 at 12:07 PM
thank you, but I don't want the property to be synced across all GameObjects, I explain more
class Columns
{
var affectedColumnLenth:int;
var selectedColumn:GameObject;
public var columnCurentSituation:int;//-1 =down , 1=top
function get ColumnCurentSituation():int
{
return columnCurentSituation;
}
function set ColumnCurentSituation(value:int)
{
columnCurentSituation=value;
}
function up()
{
columnCurentSituation=1;
print("UP");
}
function down()
{
columnCurentSituation=-1;
print("Down");
}
function ColumnUpAndDown(columnCurentSituation,affectedColumns)
{
if(columnCurentSituation==-1)
{
up();
}
if(columnCurentSituation==1)
{
down();
}
}
}
var column:Columns;
var affectedColumns:Columns[];
function OnMouseDown()
{
column.ColumnUpAndDown(column.columnCurentSituation,column.affectedColumns);
for(var i:int=0;i<column.affectedColumnLenth;i++)
{
if(affectedColumns[i].columnCurentSituation==1)
{
//
}
if(affectedColumns[i].columnCurentSituation==-1)
{
//
}
affectedColumns[i].columnCurentSituation=-column.columnCurentSituation;
print(affectedColumns[i].selectedColumn.name.ToString());
}
}
for example attach this code to tow object "A" and "B" in below code "columnCurentSituation" change only "A" when I click on "A", I want columnCurentSituation change in "B" too.
affectedColumns[i].columnCurentSituation=-column.columnCurentSituation;
any help?
Your answer
Follow this Question
Related Questions
Object from flash to unity 2 Answers
How to change an object's property from another script 0 Answers
Add custom properties to Objects 1 Answer
How to create Prefab with property 2 Answers