Quantcast
Channel: Questions in topic: "get"
Viewing all articles
Browse latest Browse all 215

Getter Working, Setter not.

$
0
0
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.

Viewing all articles
Browse latest Browse all 215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>