Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Getters and Setters with an array

Discussion in 'Scripting' started by Afropenguinn, Oct 26, 2014.

  1. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    I have an array of classes, and whenever you set one I want to set a variable in that class.
    Code (CSharp):
    1.  
    2. public ActorAbility abilities[int pos]
    3.     {
    4.         set
    5.         {
    6.             _abilities[pos] = value;
    7.             _abilities[pos].actor = this.actor;
    8.         }
    9.         get
    10.         {
    11.             return _abilities[pos];
    12.         }
    13.     }
    14.     private ActorAbility[] _abilities = new ActorAbility[4];
    15.  
    However I just can't get it to work, as it wants to set the array but not the value in the array. How do I get it to set a value within the array?