C sharp get and set problem: "name doesn not exist in the current context
Hello,
i got a problem with my code. I tried to make a get/set function for my life variable, but the get, set and value is always marked as red, with the information: "The name get does not exist in the current context"
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
private int life;
//return the life value
public int Life() {
get
{
return life;
}
set{
life = value;
}
}
}
Comment
Best Answer
Answer by TreyH · Mar 15, 2016 at 03:16 PM
It's thinking Life is a function because of your parentheses. :-) Use:
public int Life {
get
{
return life;
}
set{
life = value;
}
}
oh i thank you! First time i use a getter and setter :))