EngediKimHyeYoung / Unity

0 stars 0 forks source link

미끄러지는 캐릭터 #23

Open EngediKimHyeYoung opened 1 year ago

EngediKimHyeYoung commented 1 year ago

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro;

public class Move3 : MonoBehaviour { private Rigidbody2D rb; private bool moveLeft; private bool moveRight; private float speed = 1; public TextMeshProUGUI ScoreText; public TextMeshProUGUI Text; public TextMeshProUGUI StateText; public Vector3 newPosition; private Animator animator;

void Start()
{
    rb = GetComponent<Rigidbody2D>();
    animator = GetComponent<Animator>();
    moveLeft = false;
    moveRight = false;
}
public void PointerDownLeft()
{
    this.transform.localScale = new Vector2(-1,1);
    animator.SetBool("RunStart", true);
    moveLeft = true;
}
public void PointerUpLeft()
{
    moveLeft = false;
    newPosition = new Vector3((this.transform.position.x - 3), this.transform.position.y, this.transform.position.z);
    iTween.MoveTo(this.gameObject, iTween.Hash("position", newPosition, "easetype", iTween.EaseType.easeOutQuad, "time", 1.0f));
}

public void PointerDownRight()
{
    this.transform.localScale = new Vector2(1,1);
    animator.SetBool("RunStart", true);
    moveRight = true;
}
public void PointerUpRight()
{
    newPosition = new Vector3((this.transform.position.x + 3), this.transform.position.y, this.transform.position.z);
    iTween.MoveTo(this.gameObject, iTween.Hash("position", newPosition, "easetype", iTween.EaseType.easeOutQuad, "time", 1.0f));
    moveRight = false;
}

void Update()
{
   MovePlayer(); 
}

private void MovePlayer()
{
    if(moveLeft)
    {
        speed = speed - 0.07f;
    }
    else if(moveRight)
    {
        speed = speed + 0.07f;
    }
    else 
    {
        speed = 0; 
        animator.SetBool("RunStart", false);
    }
}

private void FixedUpdate()
{
    Text.text = "position: "+ this.transform.position;
    ScoreText.text = "Speed:" + speed;
    rb.velocity = new Vector2(speed, rb.velocity.y); 
}

}