Hi I am new to unity and I am making a simple 2D bowling game using c# script. however I cannot find any c# script code that can help me reset the position of the bowling ball and the pins. can anyone help me with this? thx
Could save your original positions in a variable to reset to?
Vector3 ballStartingLocation = (9,4,4);
transform.position = ballStartingLocation;
Also for 2D you would use Vector2.
Vector3 ballStartingLocation = (9,4);
transform.position = ballStartingLocation;
Sure you can.
Vector3 defaultPos;
void Start(){
defaultPos = transform.position;
}
//when you want to reset it
transform.position = defaultPos;
Position your pins in the editor.
Attach a script to the pins and the ball that Cache the Gameobject.transform.position into a private Vector3(), best to do this inside the Start() function.
Write a function similar to this :
public void ResetPosition()
{
gameObject.transform.position = cachedPosition;
}
Call that function whenever you want to reset the position.
You may want to include rotation in this as the pins will keep their rotation when reset. If you need help with that come back, otherwise I recommend trying it yourself
Obviously if you’re making a 2D game you will use a Vector2()
Goodluck