i am making a RPG game with some other people and the HP is worked put by two stats from a class added together then halfed, can i have all the classes in one script and then call the stats as needed from the said class in the script?
No clue what you are asking.
for example if i have a script with
public void Assassin(){
ClassName = “Assassin”;
Force = 9;
Vitality = 26;
Agility = 30;
Fortiude = 18;
Intellect = 31;
Rationale = 13;
Charisma = 8;
}
public void Shapeshifter(){
ClassName = “Shapehifter”;
Force = 17;
Vitality = 17;
Agility = 17;
Fortiude = 17;
Intellect = 17;
Rationale = 17;
Charisma = 17;
}
public void Monster(){//non human
ClassName = “Monster”;
Force = 32;
Vitality = 32;
Agility = 32;
Fortiude = 32;
Intellect = 32;
Rationale = 32;
Charisma = 32;
}
can i then go in another script
public float Maxhealth;
void start(){
Maxhealth = cs.Monster().Fortiude
}
or something like that for example
If your asking about accessing something like ScriptA accessing variables in ScriptB on a different game object then yes. Any variable you want to be seen by other script should be public. So instead of…
int force = 32;
you want to have
public int force = 32;
Then lets say you have a magic user that will reduce the force in the monster script by half. In you magicUserScript you would have something like this.
void magicDudeSpell(){
monsterScript mScript = GameObject.Find("monsterBob").GetComponent<monsterScript>();
mScript.force = 16;
}
What is happening here is that you are creating a new script called mScript from the script monsterScript. You may have lots of monster scripts out there so you search for the one you want using the GameObject.Find(“What I am looking for”). Then you put a period after that and GetComponent< >. Components are the components is the list that is attached to your GameObject like transform and the script that you have attached to it. Using the GetComponent is how you access that list. in-between the < > is what you are looking for. In this case, the monster has a script attached called monsterScript. After that it is important to put the () and then semicolon ;
Now as long as you variables and methods are public, you can access them with the mScript, or what ever you call your variable. If this is confusing I recommend that you look at some tutorial videos. If you don’t have a lot of programming experience your better off putting the game on hold and learn programming. You will find it much easier to make games when you know how to code.
The way it was written in your original example is not possible exactly as shown. You cannot access a method’s local variable in that way.
If thats not psuedo code for how your handling diffferent classes & their data I highly recommend you don’t start with an rpg (Or if you’ve got a more experienced programmer get them to give some direction for this stuff). Do something simpler to get some experience programming (Look at the Unity tutorials like larswik suggested), rpgs generally require alot of complex & robust systems that are a not for beginners.
i have experience just not in a rpg other than that im fine iv been through all the tutorials 5 times over
so i need a different script for each class to access their stats?
Since your stats are the same per class you can just have class called stats (May be worth making Stats a ScriptableObject) that each class has.
That way you can pass around the stats without needing to know the class.
Scriptable Objects could work well for you.
You could have regular classes, too. I didn’t fully grasp how you were using the class, other than your small question/example.
If you’re still looking for some input or what not, you could elaborate a little bit…
basicalky the HP for the characters is worked out by force +vitality /2 and now all the classes have the same numbers i was wondering if i can call the stat name from the method in a different script
Okay, well sure you can access public variables and methods from any other script…
Just in your first example, you tried to access a variable that was inside a method, which isn’t possible.
There’s an example earlier in this thread about accessing a variable from another script.
Cheers matey just wanted to know what if i could cheat the code and use do less files lol