# GoTo Script not working

**URL:** https://discussions.unity.com/t/goto-script-not-working/18105
**Category:** Questions & Answers
**Created:** [April 2, 2011, 11:07am UTC](https://discussions.unity.com/t/goto-script-not-working/18105 "2011-04-02T11:07:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zmar0519](https://avatars.discourse-cdn.com/v4/letter/z/e5b9ba/32.png) [@zmar0519](https://discussions.unity.com/u/zmar0519)
#### Post date: [April 2, 2011, 11:07am UTC](https://discussions.unity.com/t/goto-script-not-working/18105/1 "2011-04-02T11:07:54Z")

</div>

Hi everyone. I have a goto script that is attached to an empty gameObject, and that object is supposed to follow the player on the x and z axis, but not the y. However, it only works on the x axis. Any help would be appreciated. Here is my code:

```auto
var useXTransform : boolean = true;
var useYTransform : boolean = true;
var useZTransform : boolean = true;
var useXRotation : boolean = true;
var useYRotation : boolean = true;
var useZRotation : boolean = true;
var TargetObject : Transform;

function Update () 
{
    if(useXTransform)
    {
        transform.position.x = TargetObject.transform.position.x;
    }
    if(useYTransform)
    {
        transform.position.y = TargetObject.transform.position.y;
    }
    if(useZTransform)
    {
        transform.position.z = TargetObject.transform.position.z;
    }
    if(useXRotation)
    {
        transform.rotation.x = TargetObject.transform.rotation.x;
    }
    if(useYRotation)
    {
        transform.rotation.y = TargetObject.transform.rotation.y;
    }
    if(useZRotation)
    {
        transform.rotation.z = TargetObject.transform.rotation.z;
    }
}

```

---

<div class="post-metadata">

### Author: ![Statement](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/statement/32/89859_2.png) [@Statement](https://discussions.unity.com/u/Statement)
#### Post date: [April 2, 2011, 11:43am UTC](https://discussions.unity.com/t/goto-script-not-working/18105/2 "2011-04-02T11:43:35Z")

</div>

If you cant move on Z axis then you probably have forgotton to check `useZTransform` in inspector.

Your code could be probably compacted so it's easier to read.

```auto
var useXTransform : boolean = true;
var useYTransform : boolean = true;
var useZTransform : boolean = true;
var useXRotation : boolean = true;
var useYRotation : boolean = true;
var useZRotation : boolean = true;
var TargetObject : Transform;

function Update() {
    UpdatePosition();
    UpdateRotation();
}

function UpdatePosition() {
    var position = TargetObject.position;
    if (!useXTransform) position.x = 0;
    if (!useYTransform) position.y = 0;
    if (!useZTransform) position.z = 0;
    transform.position = position;
}

function UpdateRotation() {
    var rotation = TargetObject.rotation;
    if (!useXRotation) rotation.x = 0;
    if (!useYRotation) rotation.y = 0;
    if (!useZRotation) rotation.z = 0;
    transform.rotation = rotation;
}

```
