15-10-2020, Saat: 02:01
zıplama yapmaya çalıştığımda space'e abanıyorum anca 1 kere zıplıyor ve animasyon bile çalışmıyor yardımcı olursanız sevinirim
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float runSpeed, jumpForce;
public float jumpHeight = .4f;
private float moveInput;
private Rigidbody2D myBody;
private Animator anim;
public Transform groundCheck;
public LayerMask groundLayer;
private bool facingRight = true;
private Vector3 range;
void Awake()
{
myBody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
Movement();
CheckCollisionForJump();
}
void Movement()
{
moveInput = Input.GetAxisRaw("Horizontal") * runSpeed;
anim.SetFloat("Speed", Mathf.Abs(moveInput));
myBody.velocity = new Vector2(moveInput, myBody.velocity.y);
if(Input.GetKeyUp(KeyCode.Space))
if(myBody.velocity.y > 0)
{
myBody.velocity = new Vector2(myBody.velocity.x, myBody.velocity.y * jumpHeight);
anim.SetBool("Jump", true);
}
else
{
anim.SetBool("Jump", false);
}
if (moveInput > 0 && !facingRight || moveInput < 0 && facingRight)
Flip();
}
void CheckCollisionForJump()
{
Collider2D bottomHit = Physics2D.OverlapBox(groundCheck.position, range, 0, groundLayer);
if(bottomHit != null)
{
if(bottomHit.gameObject.tag == "Ground" && Input.GetKeyDown(KeyCode.Space))
{
myBody.velocity = new Vector2(myBody.velocity.x, jumpForce);
}
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 transformScale = transform.localScale;
transformScale.x *= -1;
transform.localScale = transformScale;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float runSpeed, jumpForce;
public float jumpHeight = .4f;
private float moveInput;
private Rigidbody2D myBody;
private Animator anim;
public Transform groundCheck;
public LayerMask groundLayer;
private bool facingRight = true;
private Vector3 range;
void Awake()
{
myBody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
Movement();
CheckCollisionForJump();
}
void Movement()
{
moveInput = Input.GetAxisRaw("Horizontal") * runSpeed;
anim.SetFloat("Speed", Mathf.Abs(moveInput));
myBody.velocity = new Vector2(moveInput, myBody.velocity.y);
if(Input.GetKeyUp(KeyCode.Space))
if(myBody.velocity.y > 0)
{
myBody.velocity = new Vector2(myBody.velocity.x, myBody.velocity.y * jumpHeight);
anim.SetBool("Jump", true);
}
else
{
anim.SetBool("Jump", false);
}
if (moveInput > 0 && !facingRight || moveInput < 0 && facingRight)
Flip();
}
void CheckCollisionForJump()
{
Collider2D bottomHit = Physics2D.OverlapBox(groundCheck.position, range, 0, groundLayer);
if(bottomHit != null)
{
if(bottomHit.gameObject.tag == "Ground" && Input.GetKeyDown(KeyCode.Space))
{
myBody.velocity = new Vector2(myBody.velocity.x, jumpForce);
}
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 transformScale = transform.localScale;
transformScale.x *= -1;
transform.localScale = transformScale;
}
}