Issue with transform

Hi there, newbie on unity trying to make Bridge Race to learn stacking mechanics. I’ve just done stacking up into character & stair down but there is an issue with stair stacking, it’s rotation changes with where my player looks even I give localRotation of referenceStair which is already in scene before game start. Here is my project’s ss and codes I hope someone can give me a way to fix this.

    public static CollectManager instance;
    public Transform refStair;
    private Stack<GameObject> collectedStack = new Stack<GameObject>();
    [SerializeField] private GameObject poppedStack;
    [SerializeField] private float distanceObjects;
    [SerializeField] private Transform prevObject, lastStack;
    [SerializeField] private Transform parent;
    int counter = 0, counter2 = 0;

   
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
    }
    void Start()
    {
        distanceObjects = prevObject.localScale.y;
        lastStack.localPosition = refStair.localPosition;
    }

   
    void Update()
    {

    }

    public void CollectUp(GameObject collectedObject, bool needTag = false, string tag = null, bool downOrUp = true)
    {
        collectedStack.Push(collectedObject);
        Debug.Log(collectedStack.Count);
        counter++;
        if (needTag)
        {
            collectedObject.tag = tag;
        }
        collectedObject.transform.parent = parent;
        Vector3 desPos = prevObject.localPosition;
        //desPos.y += downOrUp ? distanceObjects : -distanceObjects;
        desPos.y = distanceObjects * counter;
        collectedObject.transform.DOLocalJump(desPos, 0.4f, 1, 0.2f); //collectedObject.transform.localPosition = desPos;
        collectedObject.transform.localRotation = prevObject.localRotation;
        //prevObject = collectedObject.transform;
    }

    public void StairManage(string tag = null, bool downOrUp = true)
    {
        if (collectedStack.Count != 0)
        {
            counter--;
            counter2++;
            Vector3 desPos2 = lastStack.transform.localPosition;
            poppedStack = collectedStack.Pop();
            poppedStack.tag = tag;
            poppedStack.transform.localScale = refStair.localScale;
            desPos2.y = refStair.transform.localScale.y * counter2;
            desPos2.z = refStair.transform.localScale.z * counter2;
            poppedStack.transform.DOLocalJump(desPos2, 0.2f, 1, 0.2f);
            poppedStack.transform.localRotation = refStair.transform.localRotation;
            poppedStack.transform.parent = null;
            lastStack = poppedStack.transform;
        }
    }

8380191--1104975--upload_2022-8-22_11-46-56.png

Player’s collect manager script
8380191--1104978--upload_2022-8-22_11-47-45.png

This transform side of Unity is really confusing me too much.

Had to google what ‘Bridge Race’ was. Shows how little I play mobile games. Which is exactly zero.

I wouldn’t even bother coding the functionality to place blocks. Just have them already placed and marked as inactive.

Then if the player is holding one as they walk into a trigger, you just destroy one off their back and make the next stair active.

Yeah I was thinking about same way to make stairs but then I wouldn’t want to hold many objects for it, decided to make it in this way, I don’t wanna do it by just watching video without adding my opinions in it. Just couldn’t figure it out why rotation changes with player’s direction. Still thanks for your solution idea.

You’re over complicating what should be a simple thing. Sometimes the solution isn’t to solve what you’re trying to do, but find a better way to do it.

There’s no point in overcomplicating something just to be different to what already exists.

I understand but there will be different levels and those many objects won’t be good for optimization, there will be 11x stair area so that’s mean too many hidden object in project that’s why I choose this way.

This is pre mature optimisation. There are much more worthwhile optimisations to worry about than a few hundred inactive game objects, which, by the way, will hardly be an issue.

Just fixed with changing rotation code with eulerAngles now it working fine