[Solved] Question about SceneManager [C#]

Hi

I think my question might be tough to answer, but this is it:
(maybe I’ll have some clues or links that might be helpful to figure it out)

I use this script at the end of a simple flappy bird prototype:

        if (restart && Input.GetKeyDown (KeyCode.R))             
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene("MyGame");
}

It’s working great, BUT, not everything is getting back to “0”, some background for instance are scrolling from the value they were before pressing R to restart, instead of getting back to were they should begin each time (when you press the PLAY button to start it the 1st time).

Would you know why these few elements are doing so please ?
I guess it’s link to the script that is driving them?

Thx a lot.

Krousty, the things which are staying the same, are they materials? Shared assets changes will stay between scenes. Either that or you could have a script with DontDestroyOnLoad, but I think you’d remember something like that. It should be a full refresh. What exactly is staying the same?

By the way, when I say a shared asset. I mean an asset which isn’t fixed purely to one instance of an object, like a material for example. When you have a material, and make changes to that same material, you’ll notice all the objects with that material also have the same change. This could be what you’re experiencing. If so, just have a method call to set them back to 0 on void Start().

Well, I am not using a scroll by moving the texture anymore, it’s really a moving object.
It seems only the scrolling elements of this script are not reseting

using UnityEngine;
using System.Collections;

public class BGScroller : MonoBehaviour
{
    public float scrollSpeed;
    public float tileSizeX;
    public float scrollSpeedUP;

    private Vector3 startPosition;
    private GameObject player;

    void Start ()
    {
        startPosition = transform.position;
        player = GameObject.Find ("MyHero");
    }

    void Update ()
    {

        Transform playerTransform = player.transform;
        float BgYPosition = -playerTransform.position.y -3f;
        Vector3 scrollY = new Vector3 (0f,BgYPosition * scrollSpeedUP,0f);

        float newPosition = Mathf.Repeat (Time.time * scrollSpeed, tileSizeX);
        Vector3 scrollX = startPosition + Vector3.left * newPosition;
        transform.position = scrollX + scrollY;
    }
}

I was reading this too
http://forum.unity3d.com/threads/any-way-to-reset-the-scene.23986/#post-159099

Maybe that can help me.

OK, I found the solution \o/
I’m using Time.timeSinceLevelLoad instead of Time.time
so to quote the previous exemple, I just change this line 26, and everything is working great now :).

        float newPosition = Mathf.Repeat (Time.timeSinceLevelLoad * scrollSpeed, tileSizeX);

(I used this post to help me)

1 Like