Getter Working, Setter not.

using UnityEngine;
using System.Collections;

public class BaseSkills : MonoBehaviour
{
int strBase = 1;

public int Strength {
		get{ return strBase; }
		set{ strBase = value; }
	}

Top is my getter and setter code. Where Strength base value is 1.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class AttributesSetup : MonoBehaviour
{
public int strMin;
public int myClass;
BaseSkills class1;

	public void StrMin (int strMin) {
        class1.Strength = 5;
        print(class1.Strength); // I get 5

	}
// Here I set the Strength value to 5.

	public void Strength (int strengthLevel)
	{
		print(class1.Strength); // I get 1
	}

Here I retrieve the value and get 1 and not 5, if I print after I set the value I get value 5.

I need the value set, so I can use the set value everywhere in any script. This is my first day in using getters and setters. I omitted some codes so its easier reading.

Your StrMin method receives an strMin integer value that’s never used, then changes the Strength property of class1 to 5 and prints it.

Your Strength method (in AttributesSetup) receives one strengthLevel value that’s never used, and the prints class1.Strength value.

The missing info here is the code that calls StrMin and/or Strength, if you call Strength before StrMin, nothing else (at least in the code you showed) will change it’s default value of 1.

Also, you are saying that the setter is not working but as you see when calling StrMin, the setter DOES work, if it wasn’t working you wouldn’t be getting a “5” printed.

Check again that you call Strength (the method of AttributesSetup) after you’ve set the Strength (the property of class1) to a different value. If it’s still not working share some more code to find the real problem.

The get/set property looks OK. So it must be something else, from the code you’re showing, it looks like the Strength function simply prints out class1’s Strength, which by default would be 1.

 public void Strength (int strengthLevel)
 {
     class1.Strength = strengthLevel;  //add this to set the strength
     print(class1.Strength);
 }

need more codes, what’s the order that you’re calling these? Not enough info to be certain.

The problem was solved at this post.