Я делаю игру в стиле Flappy Bird, и Rigidbody2D.simulated устанавливает значение false после нажатия кнопки Play, чтобы протестировать приложение.Куда я должен поместить rigidbody.simulated = true
, чтобы убедиться, что он остается таким, и я могу выключить его позже?
Если я поставлю это в void Update()
, то void OnTriggerEnter2D(Collider2D collision)
не будет работать так, как должно.
Rigidbody2D rigidbody;
Quaternion downRotation;
Quaternion forwardRotation;
void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
//it doesn't work if I put it here
downRotation = Quaternion.Euler(0,0,-90);
forwardRotation = Quaternion.Euler(0, 0, 35);
}
void Update()
{
//if I put it here then void OnTriggerEnter2D() will not work
if (Input.GetMouseButtonDown(0))
{
transform.rotation = forwardRotation;
rigidbody.AddForce(Vector2.up * tapForce, ForceMode2D.Force);
}
transform.rotation = Quaternion.Lerp(transform.rotation, downRotation, tiltSmooth * Time.deltaTime);
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "ScoreZone")
{
// ToDo: register a score event
// Play a sound
}
if (collision.gameObject.tag == "DeadZone")
{
rigidbody.simulated = false;
//register a dead event
//play a sound
}
}
}