Hello, i try to make charakter making script. To change robes for example… this is the script:
var shirt : Transform[];
private var currentShirt : int;
var top : Transform; //vieta kur turetu but marskineliai
var change = false;
function Update()
{
var object : shirt[currentShirt];
if(change)
{
Instantiate (object, top.transform.position, Quaternion.identity);
change = false;
}
}
function OnGUI()
{
if (GUI.Button(Rect(10,10,50,30),"Previous"))
{
currentShirt--;
change = true;
}
else if (GUI.Button(Rect(10,70,50,30),"Next"))
{
currentShirt++;
change = true;
}
}
and i have error in this line: var object : shirt[currentShirt];
error: Assets/Changer.js(8,27): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Any ideas?
The line “var object : shirt[currentShirt];” is not correct syntax.
Were you maybe trying to do this intead?
var object : Transform = shirt[currentShirt];
OK Thanks its working. But did you know how to atach created object to “top” ?
Couple of things. When changing objects, you first want to destroy the object that is there. I would use the object variable to house the current shirt, the % sign will help in constraining your choice to the bounds of the array.
In my example code, I used the Start function to initialize the shirt to a random shirt in the array.
Hope this helps
var shirt : Transform[];
var top : Transform;
private var currentShirt : int=-1;
private var change = false;
private var object : Transform;
function Start()
{
currentShirt=Mathf.Floor(Random.value * shirt.length);
change=true;
}
function Update()
{
if(change)
{
if(object!=null)Destroy(object.gameObject);
object=Instantiate (shirt[currentShirt], top.transform.position, Quaternion.identity);
change = false;
}
}
function OnGUI()
{
if (GUI.Button(Rect(10,10,50,30),"Previous"))
{
currentShirt--;
change = true;
}
else if (GUI.Button(Rect(10,70,50,30),"Next"))
{
currentShirt++;
change = true;
}
currentShirt=currentShirt % shirt.length;
}
can you explain me some things?
var shirt : Transform[];
var top : Transform;
private var currentShirt : int=-1;
private var change = false;
private var object : Transform;
function Start()
{
currentShirt=Mathf.Floor(Random.value * shirt.length); // that does it mean
change=true;
}
function Update()
{
if(change)
{
if(object!=null)Destroy(object.gameObject); //what do that object!=null
object=Instantiate (shirt[currentShirt], top.transform.position, Quaternion.identity);
change = false;
}
}
function OnGUI()
{
if (GUI.Button(Rect(10,10,50,30),"Previous"))
{
currentShirt--;
change = true;
}
else if (GUI.Button(Rect(10,70,50,30),"Next"))
{
currentShirt++;
change = true;
}
currentShirt=currentShirt % shirt.length; //WTF "%" ? what it means
}
thanks for script 
P.S. and how to parent that shit to top (empty game object)
theShirt.transform.parent = top;
Assets/NewBehaviourScript.js(19,23): BCE0019: ‘transform’ is not a member of ‘UnityEngine.Transform[ ]’.
I changed object.transform.parent = top;
and working
object.transform.parent = top.transform;
I said “theShirt”, not “shirt”, as in, the specifically targeted shirt. Glad you got it working.
By the way, don’t use the variable name “object”; it’s very easy to confuse that with the type “Object” (or “object” in C#)