simple script

Ok this is my first time attempting to write a script in unity, all i want is an object to move up and down. ive tried different variations of this script and nothing seems to work.

function Update () {
for (var child : Transform in transform) {
child.position += Vector3.up * 1;
if (child.position > Vector3.up *118) { child.position -= Vector3.up * 1; }}}
else
if (child.position < Vector3.up * 108) { child.position += Vector3.up * 1; }}

The code you’ve got there is probably more complicated than you really need. The first main problem is that you are comparing two vectors using less-than and greater-than, but these operations aren’t defined for vectors. If you want the object to move up and down, the Y coordinate is what you are really interested in. Also, you don’t need to move the children of an object individually; the idea is that when you move the parent, all the children are moved along with it:-

function Update () {
    if (child.position.y > Vector3.up *118) {
        child.position -= Vector3.up;
    }
    else if (child.position.y < Vector3.up * 108) {
        child.position += Vector3.up;
    }
}

aha, that makes perfect sense, i come from a high level interpreted language so its way different for me.