Hi, I’m Julian. I have a problem changing body types via script. The thing is that when I try to change it from static to dynamic, and then back to static, it stays at dynamic.
Here’s that code:
public class Ball : MonoBehaviour
{
[HideInInspector] public bool playing;
// Start is called before the first frame update
void Start()
{
playing = false;
Physics2D.gravity = new Vector2(0, -9.8f);
this.gameObject.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
}
public void play()
{
playing = true;
this.gameObject.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
}
public void reload()
{
playing = false;
gameObject.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
}
public void BackToMenu()
{
SceneManager.LoadScene("Level Selector", LoadSceneMode.Single);
}
}
I don’t have any idea if I’m doing something wrong or if I’m missing something.
Please help.
-Julian