onurgunes
Hectopat
- Katılım
- 25 Kasım 2020
- Mesajlar
- 78
- Çözümler
- 1
CS8803: Top-level statements must precede namespace and type declarations.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
C#:
public class CharacterMove : MonoBehaviour
{
// Start is called before the first frame update
public float moveSpeed;
private Animator anim;
private Rigidbody2D rb2d;
float moveHorizontal;
public bool facingRight;
public float jumpForce;
public bool is Grounded;
public bool canDoubleJump;
void Start()
{
moveSpeed = 5;
moveHorizontal = Input.GetAxis("Horizontal");
anim = GetComponent<Animator>();
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
CharacterMovement();
CharacterAnimation();
CharacterAttack();
CharacterJump();
}
void CharacterMovement()
{
moveHorizontal = Input.GetAxis("Horizontal");
rb2d.velocity = new Vector2(moveHorizontal * moveSpeed, rb2d.velocity.y);
}
void CharacterAnimation()
{
if (moveHorizontal > 0)
{
anim.SetBool("isRunning", true);
}
if (moveHorizontal == 0)
{
anim.SetBool("isRunning", false);
}
if (moveHorizontal < 0)
{
anim.SetBool("isRunning", true);
}
if (facingRight == false && moveHorizontal > 0)
{
CharacterFlip();
}
if (facingRight == true && moveHorizontal < 0)
{
CharacterFlip();
}
}
void CharacterFlip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
void CharacterAttack()
{
if (Input.GetKeyDown(KeyCode.E))
{
anim.SetTrigger("isAttack");
}
}
}
void CharacterJump()
{
if (Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool("isJumping", true);
}
}
Son düzenleyen: Moderatör: