Unity 2D karakter yönü değiştirme

Samet_Efe

Decapat
Katılım
22 Aralık 2020
Mesajlar
28
Daha fazla  
Cinsiyet
Erkek
Merhabalar,
Unity üzerinde yeni çalışmaya başladım. Platform oyunu tarzı bir şeyler yapmayı deniyorum.
Karakter sol ok veya a tuşuna basınca yatay olarak 180 derece dönsün ve o tarafa bakıyormuş gibi gözüksün istedim. Ama döndürmeye çalıştığımda karakterin konumu yatay olarak değişiyor.
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    Rigidbody2D rgb;
    Vector3 velocity;

    float speedAmount = 5f;
    float jumpAmount = 3f;

    // Start is called before the first frame update
    void Start()
    {
        rgb = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        velocity = new Vector3(Input.GetAxis("Horizontal"), 0f);
        transform.position += velocity * speedAmount * Time.deltaTime;

        if (Input.GetButtonDown("Jump") && Mathf.Approximately(rgb.velocity.y, 0))
        {
            rgb.AddForce(Vector3.up * jumpAmount, ForceMode2D.Impulse);
        }

        if (Input.GetAxisRaw("Horizontal") == -1)
        {
            transform.rotation = Quaternion.Euler(0f, -180f, 0f);
        }
        else if (Input.GetAxisRaw("Horizontal") == 1)
        {
            transform.rotation = Quaternion.Euler(0f, 0f, 0f);
        }
    }
}
Kullandığım kod bu şekilde.
1651079267597.png

Karakteri hareket ettirecek script player objesinde ekli.
Şimdiden teşekkür ederim.
 

Yeni konular

Geri
Yukarı