Eki Görüntüle 1620212
Evet Hocam yeni objeler düşüyor.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour
{
[SerializeField] private float speed = 10f;
[SerializeField] private float jumpforce = 5f;
private Rigidbody2D _rigidbody2D;
private Animator _animator;
private bool grounded;
private bool Started;
private bool jumping;
private void Awake()
{
_animator = GetComponent<Animator>(); //caching
_rigidbody2D = GetComponent<Rigidbody2D>();
grounded = true;
}
private void Update()
{
if (Input.GetKeyDown("space"))
{
if (Started && grounded)
{
_animator.SetTrigger("jump");
grounded = false;
jumping = true;
}
else
{
_animator.SetBool("GameStarted", true);
Started = true;
}
}
_animator.SetBool("Ground", grounded);
}
private void FixedUpdate()
{
if (Started)
{
_rigidbody2D.velocity = new Vector2(speed, _rigidbody2D.velocity.y);
}
if (jumping)
{
_rigidbody2D.AddForce(new Vector2(0f, jumpforce));
jumping = false;
}
}
private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Ground"))
{
grounded = true;
}
}
}