Home > Blockchain >  A get or set accessor is expected
A get or set accessor is expected

Time:02-11

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

CodePudding user response:

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; }

CodePudding user response:

Typo?

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

should be

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

CodePudding user response:

on line 12 you have a typo,:

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

You might want to modify it to:

public float AttackRange { get {return attackRange;}  set { attackRange = value; }}

or

  public float AttackRange { get; set; }
  • Related