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;
}
}
Player’s collect manager script
This transform side of Unity is really confusing me too much.