void FixedUpdate()
{
BugFix();
}
void Update()
{
Walk();
BugFixFPS();
}
void BugFixFPS()
{
if ((onGround) && !JumpControl)
{
CleanVectorY = true;
}
else
{
CleanVectorY = false;
}
}
void BugFix()
{
if ((onGround) && !JumpControl)
{
CleanVectorY = true;
}
else
{
CleanVectorY = false;
}
}
void Walk()
{
movement.x = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(movement.x * Speed, rb.velocity.y);
if (movement.x < 0 && Right == true)
{
Flip();
Debug.Log("в лево");
}
else if (movement.x > 0 && Right == false)
{
Flip();
Debug.Log("в право");
}
}
public void Flip()
{
if (CleanVectorY)
{
rb.velocity = new Vector2(rb.velocity.x, 0);
Debug.Log("Очистить вектор");
}
Vector3 scale = transform.localScale;
scale.x *= -1;
transform.localScale = scale;
Right = !Right;
}
void Jump()
{
if (Input.GetKey(KeyCode.Space))
{
if (onGround)
{
if (!JumpControl)
{
rb.velocity = new Vector2(rb.velocity.x, 0);
Debug.Log("Обновление вектора => Прыжок");
}
JumpControl = true;
}
}
else
{
JumpControl = false;
}
if (JumpControl)
{
if ((JumpTime += Time.fixedDeltaTime) < JumpControlTime)
{
rb.AddForce(Vector2.up * JumpForce / (JumpTime * 10));
}
}
else
{
JumpTime = 0;
}
if (onGround)
{
MomentJumpCount = 0;
}
}
//BugFix
public bool CanSlide = false;
public PhysicsMaterial2D NoSlide;
public PhysicsMaterial2D Slide;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
BugFix();
}
void BugFix()
{
if (movement.x == 0 && !CanSlide)
{
rb.sharedMaterial = NoSlide;
}
else
{
rb.sharedMaterial = Slide;
}