Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

A get or set accessor is expected

using System.Collections.Generic;
using UnityEngine;

public class playercombat : MonoBehaviour
{

    public Animator animator;
    public Transform attackPoint;
    public float attackRange = 0.5f;
    public LayerMask enemyLayers;

    public float AttackRange { get => attackRange; 0.5f => attackRange = 0.5f; }
   

    // Update is called once per frame
    void Update()
    {
       if (Input.GetKeyDown(KeyCode.Q))
        {
            Attack();
        }
    }
    void Attack()
    {
        animator.SetTrigger("Attack");

        Physics2D.OverlapCircleAll(attackPoint.postion, AttackRange, enemyLayers);

        foreach (Collider2D enemy in hitEnemies) 
        {
            Debug.lot("Hit" + enemy.name);
        }
    }
    void OnDrawGizmosSelected()
    {
        if (attackPoint == null)
            return;
        Gizmos.DrawWireSphere(attackPoint.position, AttackRange);
    }
}


A get or set accesssor expected. What does that mean and how should I fix it?
Assets\playercombat.cs(13,52): error CS1014: A get or set accessor expected
Assets\playercombat.cs(13,60): error CS1014: A get or set accessor expected

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Your setter on AttackRange is weird. KYL3R’s answer implies that you want to set attackRange to 0.5f whenever you set it, no matter what you set it to. That seems equally weird. I think you want

public float AttackRange { get => attackRange; set => attackRange = value; }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading