YahyaMeYes
Hectopat
- Katılım
- 3 Ekim 2021
- Mesajlar
- 34
Daha fazla
- Cinsiyet
- Erkek
Merhaba. Unity üzerin 2D platform oyunu yapıyordum sağa gidince sağ baksın sola gidince sola gitsin diye kodlar baktım internetten baktım yazdım ama sağ tuşa basınca ışınlanıyor sol tuşa basınca geri geliyordu. Technopat'te böyle makaleler varmış ama cevabı bulamadım işte kodlar;
Kod:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour.
{
Rigidbody2D rgb;
Vector3 velocity;
float speedAmount = 5f;
float jumpAmount = 5f;
// 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);
}
}
}
Son düzenleyen: Moderatör: