using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField]
public static PlayerController instance;
public Rigidbody2D rb;
public SpriteRenderer SR;
public Transform GroundCheckPoint;
public float moveSpeed;
public float JumpForce;
public float sprintForce;
public float dashSpeed = 15f; // 冲刺速度
public float dashDuration = 0.2f; // 冲刺持续时间
public float dashCooldown = 1f; // 冲刺冷却时间
private bool isDashing = false; // 是否正在冲刺
private float dashStartTime; // 冲刺开始时间
private bool canDash = true; // 是否可以冲刺
private bool canJump = true;
private bool isJumping;
public LayerMask whatIsGround;
public bool isGround;
private Animator animator;
Vector2 moveDir;
Vector2 moveAmount;
private void Awake()
{
instance = this;
}
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
SR = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
moveDir = new Vector2(Input.GetAxis("Horizontal"),0);
moveAmount = moveDir * moveSpeed * Time.deltaTime;
//
网页链接 = new Vector2(horizontalInput * moveSpeed, rb.velocity.y);//move to left and right
isGround = Physics2D.OverlapCircle(GroundCheckPoint.position, .2f, whatIsGround);//检测角色是否在地面
if (Input.GetButtonDown("Jump") && canJump)//跳跃
{
canJump = false;
isJumping = true;
}
if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
{
}
if (moveDir.x > 0 )//flip sprite
{
网页链接 = false;
}else if(moveDir.x < 0 )
{
SR.flipX=true;
}