using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMove : MonoBehaviour
{
public AudioSource JumpSoundeffect;
Rigidbody2D rb;
public float speed;
public float jumps;
public float xInput;
private SpriteRenderer sprite;
public bool yes;
private Animator anim;
public LayerMask groundlayer;
private BoxCollider2D coll;
//bool isground;
// Start is called before the first frame update
void Start()
{
xInput = 0f;
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
sprite = GetComponent<SpriteRenderer>();
coll = GetComponent<BoxCollider2D>();
}
// Update is called once per frame
public void Update()
{
// float xInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(xInput * speed, rb.velocity.y);
// isground = Physics2D.OverlapCircle(Groundcheck.position,0.2f,groundlayer);
// jumpPlayer();
if(xInput <0)
{
sprite.flipX = true;
}
else if (xInput >0)
{
sprite.flipX = false;
}
/* if(Input.GetButtonDown("Jump") && isground())
{
JumpSoundeffect.Play();
rb.velocity = new Vector2(rb.velocity.x,jumps);
}
if(xInput > 0f)
{
anim.SetBool("Running",true);
}
else if (xInput < 0f)
{
anim.SetBool("Running",true);
}
else
{
anim.SetBool("Running",false);
}
*/
}
private bool isground()
{
return Physics2D.BoxCast(coll.bounds.center,coll.bounds.size,0f,Vector2.down,.1f,groundlayer);
}
public void jumpPlayer()
{
if( isground())
{
JumpSoundeffect.Play();
rb.velocity = new Vector2(rb.velocity.x,jumps);
}
}
public void GoLeft()
{
xInput=-1;
}
public void GoRight()
{
xInput=1;
}
public void UpButton()
{
xInput = 0;
}
}
No comments:
Post a Comment