Alight, I apologize that this will be a rather dumb question, but I am trying to gain a full understanding of the purpose and use of objects. Specifically I am working in Unity, but I am not sure that this matters. Also, I should also mention that the language is rather overwhelming. But here is the simple example that I am working on.
public class Player : MonoBehaviour
{
private string name = "Players Name";
private void Start () {
var nexus = new Player();
}
public static void Using() {
// how are these different?
Attack();
this.Attack();
}
public static void Move() {
print ("The player is moving");
}
private void Attack () {
print ("The player is attacking");
}
}
public class UsingStuff : MonoBehaviour
{
private void Start () {
Player.Move();
}
}
So here are the questions:
- What is the difference between calling a function Attack() versus this.Attack? From a novice perspective, they would seem to do exactly the same thing. However, I am assuming that my example is just too simplistic.
- I created the object of the Player class with the random name nexus. However, when I call a function from a different class I seem to use the class name rather than this variable name. So what is the purpose of creating a variable name?
I will leave it at those two for now, as hopefully that will help with some confusion for some other things. Thank you for your help.
Playerclass member that you instantiate inStart(). Instead, you're creating a player and then throwing it away because it goes out of scope whenStart()returns.Updatefunction it it's not in use, it's worse on preformance. Also, you shouldn't include it in the Stack Overflow post as it's not relavent to your issue.