Сделал прыжок от стенки к стенке( wall jump). Долго ломал голову как сделать, но в итоге получилось вот это.
Подскажите, как оптимизировать код
public class noobscript : MonoBehaviour
private bool iswallright = false;
private bool iswallleft = false;
private bool iswallrightflip = false;
private bool iswallleftflip = false;
public LayerMask wallright;
public LayerMask wallleft;
public Transform rightwall;
public Transform leftwall;
public Transform rightwallflip;
public Transform leftwallflip;
private void FixedUpdate()
iswallright = Physics2D.OverlapCircle(rightwall.position, groundRadius, wallright);
iswallleft = Physics2D.OverlapCircle(leftwall.position, groundRadius, wallleft);
iswallrightflip = Physics2D.OverlapCircle(rightwallflip.position, groundRadius, wallright);
iswallleftflip = Physics2D.OverlapCircle(leftwallflip.position, groundRadius, wallleft);
private void Update()
if (iswallright && Input.GetKeyDown(KeyCode.Space))
{
rigidbody.AddForce(new Vector2(-300, 600));
Flip();
}
if (iswallleft && Input.GetKeyDown(KeyCode.Space))
{
rigidbody.AddForce(new Vector2(300, 600));
Flip();
}
if (iswallrightflip && Input.GetKeyDown(KeyCode.Space))
{
rigidbody.AddForce(new Vector2(-300, 600));
Flip();
}
if (iswallleftflip && Input.GetKeyDown(KeyCode.Space))
{
rigidbody.AddForce(new Vector2(300, 600));
Flip();
}
private void Flip()
{
isFacingRight = !isFacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}