Unity 2D oyununda CS0106 hatası

NoceBlen

Megapat
Katılım
1 Şubat 2014
Mesajlar
81
Çözümler
3
Selamlar herkese,
Ben Unity'de 2D platformer bir savaş oyunu yapıyorum. Vurma animasyonu ekledim şimdi de vurmak için kod yazıyordum fakat kodumda "cs0106 the modifier 'private' is not valid for this item" diye bir hata alıyorum. Daha acemi olduğum için çözümünü bulamadım. Yardım ederseniz sevinirim.

Kod:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class herorun : MonoBehaviour
{
    public float ziplama_hizi = 1f;
    public float hareket_hizi = 5f;
    public float yatayhareket;
    public int damage;

    public Animator animator;
    public Rigidbody2D rb2D;

    bool canAttack = true;
    bool faceRight = true;

    Vector2 forward;

    public Vector3 offset;
    RaycasHit2D hit;

    void Update()
    {
       
        public void Attack()
        {
            canAttack = false;
           
            if(!faceRight)
            {
                forward = transform.TransformDirection(Vector2.right * -2);
            }
            else
            {
                forward = transform.TransformDirection(Vector2.right * 2);
            }

            RaycasHit2D hit = Physics2D.RaycasHit2D(transform.position, forward, 1.0f);

            if (hit)
            {
                if(hit.transform.tag == "Enemy")
                {
                    hit.transform.getComponent<EnemyHealt>().GetDamage(damage);
                }
                else
                {
                    Debug.Log("burada bir sey yok");
                }
            }

            animator.SetTrigger("VurmaAnim");

            StartCoroutine(AttackDelay());
        }

        IEnumerator AttackDelay()
        {
            yield return new WaitForSecond(0.5f);
            canAttack = true;
        }



        if(Imput.GetKeyDown(KeyCode.F) && canAttack)
        {
            Attack();
        }

   
    }
   
}
 
Kodun her yeri hata dolu. Update içinde void çağırmışsın methodları yanlış yazmışsın raycasthit i hem yanlış yazıp hem 2 defa tanımlamaya çalışmışsın...
Hataları giderdim ama bence ilk önce acilen temel C# dersleri izle sonra oyun yapmaya başla.


Kod:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class herorun : MonoBehaviour
{
    public float ziplama_hizi = 1f;
    public float hareket_hizi = 5f;
    public float yatayhareket;
    public int damage;

    public Animator animator;
    public Rigidbody2D rb2D;

    bool canAttack = true;
    bool faceRight = true;

    Vector2 forward;

    public Vector3 offset;
    RaycastHit2D hit;

    void Update()
    {

    





        if (Input.GetKeyDown(KeyCode.F) && canAttack)
        {
            Attack();
        }


    }
    IEnumerator AttackDelay()
    {
        yield return new WaitForSeconds(0.5f);
        canAttack = true;
    }
    public void Attack()
    {
        canAttack = false;

        if (!faceRight)
        {
            forward = transform.TransformDirection(Vector2.right * -2);
        }
        else
        {
            forward = transform.TransformDirection(Vector2.right * 2);
        }

        hit = Physics2D.Raycast(transform.position, forward, 1.0f);

        if (hit)
        {
            if (hit.transform.tag == "Enemy")
            {
                hit.transform.GetComponent<EnemyHealt>().GetDamage(damage);
            }
            else
            {
                Debug.Log("burada bir sey yok");
            }
        }

        animator.SetTrigger("VurmaAnim");

        StartCoroutine(AttackDelay());
    }

}
 

Technopat Haberler

Geri
Yukarı