CaGi
Hectopat
- Katılım
- 13 Eylül 2020
- Mesajlar
- 146
Arkadaşlar bu hatayı aldım çözebilecek var mı?
Kod:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KarakterKontrolu : MonoBehaviour
{
Rigidbody2D playerRb;
Animator playerAnimator;
public float movespeed= 1f;
public float jumpSpeed = 1f;
bool facingRight = true;
// Start is called before the first frame update
void Start()
{
playerRb = GetComponent<Rigidbody2D>();
playerAnimator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
HorizontalMove();
if (playerRb.velocity.x < 0 && facingRight)
{
FlipFace();
}
else if (playerRb.velocity.x > 0 && !facingRight)
{
FlipFace();
}
if (Input.GetAxis("vertical") > 0)
{
Jump();
}
}
void HorizontalMove()
{
playerRb.velocity = new Vector2(Input.GetAxis("Horizontal") * movespeed ,playerRb.velocity.y);
playerAnimator.SetFloat("playerSpeed", Mathf.Abs(playerRb.velocity.x));
}
void FlipFace()
{
facingRight = !facingRight;
Vector3 tempLocalScale = transform.localScale;
tempLocalScale.x *= -1;
transform.localScale = tempLocalScale;
}
void Jump()
{
playerRb.AddForce(new Vector2(0f,jumpSpeed));
}
}