Есть персонаж нём два скрипта, один отвечает за что что бы игрок патрулировал платформу, другой за прыжки(если нажимаю кнопку персонаж должен подпрыгивать). По отдельности они работают, но вот вместе работает только скрипт патрулирования.
//скрипт №1
public class Moving : MonoBehaviour
{
[SerializeField] private Transform playerModelTransform;
[SerializeField] private bool isMoovingRight = true;
[SerializeField] private bool isFacingRight = true;
[SerializeField] private float speed;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
if (isMoovingRight && isFacingRight)
{
rb.velocity = new Vector2(speed, 0f);
}
else if (!isMoovingRight && !isFacingRight)
{
rb.velocity = new Vector2(-speed, 0f);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "RightBoundary")
{
isMoovingRight = false;
Flip();
}
if (collision.tag == "LeftBoundary")
{
isMoovingRight = true;
Flip();
}
}
void Flip()
{
isFacingRight = !isFacingRight;
Vector3 playerScale = playerModelTransform.localScale;
playerScale.x *= -1;
playerModelTransform.localScale = playerScale;
}
}
//скрипт №2
public class PlayerController : MonoBehaviour
{
[SerializeField] private float jumpForce;
[SerializeField] private float bigjumpForce;
private float moveInput;
private bool isGrounded;
public Transform groundCheck;
public float checkRadius;
public LayerMask whatsIsGround;
private Rigidbody2D rigidbody;
private int extraJumps;
private int extraJumpsValue;
void Start()
{
extraJumps = extraJumpsValue;
rigidbody = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatsIsGround);
}
void Update()
{
if (isGrounded == true)
{
extraJumps = extraJumpsValue;
}
if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0 && rigidbody.velocity.y > 0)
{
rigidbody.velocity = Vector2.up * jumpForce;
extraJumps--;
}
else if (Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && isGrounded == true && rigidbody.velocity.y == 0)
{
rigidbody.velocity = Vector2.up * jumpForce;
}
if (Input.GetKeyDown(KeyCode.W) && extraJumps > 0 && rigidbody.velocity.y > 0)
{
rigidbody.velocity = Vector2.up * bigjumpForce;
extraJumps--;
}
else if (Input.GetKeyDown(KeyCode.W) && extraJumps == 0 && isGrounded == true && rigidbody.velocity.y == 0)
{
rigidbody.velocity = Vector2.up * bigjumpForce;
}
}
}