private void FixedUpdate() { Vector2 targetVelocity = new Vector2(hormove * speed, rb.velocity.y); rb.velocity = new Vector2(targetVelocity.x, rb.velocity.y); }
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rb;
private float hormove = 0f;
private bool right = true;
[Header("PlayerMovementSettings")]
[Range(0,10f)]public float speed = 5f;
[Range(0,15f)]public float jumpForce = 8f;
[Space]
[Header("Ground Checker Settings")]
public bool isgrounded = false;
[Range(-5,5f)]public float checkGroundOffsetY = -1.8f;
[Range(0,5f)]public float checkGroundRadius = 0.3f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
hormove = Input.GetAxisRaw("Horizontal")* speed;
if(hormove < 0 && right)
{
flip();
}
if(hormove > 0 && !right)
{
flip();
}
if(Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(transform.up * jumpForce,ForceMode2D.Impulse);
}
}
private void FixedUpdate()
{
Vector2 targetvelocity = new Vector2 (hormove * 10f, rb.velocity.y);
rb.velocity = targetvelocity;
}
private void flip()
{
right = !right;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
private void checkGround()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(new Vector2(transform.position.x, transform.position.y + checkGroundOffsetY),checkGroundRadius);
}
}
сначала походил, а на следующий день перестал