-2

I wanted to make a vertically scrolling background with 3D assets (2D pictures works fine, but i wanted the cool lighting effect), and i kept failing doing something i though would be so simple.

so here's my current progress:

public Vector3 target;
private Transform Top_Top_Left_Rescroll;

void Start (){
    target = GameObject.FindGameObjectWithTag ("Top_Top_Left_Rescroll").GetComponent<Transform>();
}

void Update () {
    if (gameObject.transform.position.y <= -12) {
        gameObject.transform.position = new Vector3 (target.x, target.y, target.z);
    }
}

}

The object resets it's position to 0 after the if statement (the rotation and scale weren't affected), and i ran out of ideas to do what i want.

  • 1
    From Review: Please read these links before posting a question on S.O.: [How to Ask](https://stackoverflow.com/help/how-to-ask) and [How to write a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – sɐunıɔןɐqɐp Aug 07 '18 at 10:40

1 Answers1

1

You are passing a Transform to a Vector3. try :

target = GameObject.FindGameObjectWithTag("Top_Top_Left_Rescroll").transform.position;

ps: I'm not sure if you really want your target position to never change, but you are passing it's value during Start() so you will always place your gameObject in every frame at the same initial position.

Senbazuru
  • 381
  • 3
  • 14