How do i change a GameObjects position? I know about transform.position = Vector(X,Y,Z); but these are GameObjects. I want when the user starts the game or a new level the GameObjects are in a certain place. Since the GameObjects will be carrying there values from the other levels they will appear in the same place and i don’t want that. Thanks!
well a hero should probably be a class and its starting position probably be a variable in that class
you’d make a new script called Hero notice its abstract, its not going to be anything but a base its a common list of traits and functions taht all heroes will share.
public abstract class Hero
{
startpos;
health;
attack;
armor;
public attack()
{
//attack
}
public recievedamage(int damage)
{
//take in raw damage modify it based on things
//liek armor then lower hp
}
public gainhp (int hpgain)
{
//take in raw health modify it based on things
//like healing power or soemthing then raise hp
}
void Start()
{
startpos =.......;
}
}
//class ends
next script
now the hero class is a generic class basically it just says things about what heroes should have
now were going to inherit from it for specific heroes to be made notice the ::Hero that means
warrior is a hero and inherits all the things they have we can then go and put in special warrior
specific things often by simply defining stuff from hero.
For example Hero has armor as a stat but it doesnt say what armor is cause its different presumably for each hero so in here we’ll define all those stats in start to pertain to this hero.
class Warrior::Hero()
{
void start()
{
startpos = .....
armor = ....
}
}
you’ll have others like
public class ranger::hero
{
..
}
public class mage::hero
{
}
Script where you have 5 hereos picked now we’ll create a generic array of hereos.
class Pickscript()
{
hero[] HeroesChosen;
void start()
{
HeroesChosen = new Hero[5];
}
if (pick == 1)
{
HeroesChosen[0] = new Warrior();
}
}
now you have a warrior in the heroes chosen and know everything about him including startpostion
this may seem like way more work but inheritence is VERY importnat and you need to read and learn about it.
beign able later to do things like this.
hero.attack()
and it doesnt matter whether a warrior or a mage or whatever is attacking with each you have redifined attack for each so that you can just type hero.attack and it works regardless of a hero.
You can just hero.applydamage(5) and it accounts for armor and stuff thats the only way to make this managable.
Also you dont want to keep redefining stuff things like for example Health. every hero has health so you should only define it once.
take for example if i have a turret with a function that autoaims the turret.
I have turret as my base class (a base class is the base its what the other inherit from)
then i have 2 turrets, laser turret and pulse laser turret. Now both need an autoaim. well if i define it once in the base and they inherit they can both use it. But if i dont I have to define it twice by copy and pasting code basically into each class and then if i realize there is this problem where autoaim sometimes works wrong i now have to change the code in 2 or maybe 3 or 4 places and this is immpossible to keep track of. Code should never be copy and pasted if your doing that you need to pull out that snippet of code into a function and reuse it so you dont end up worrying about modifying it.
This is alot more than you asked but learning proper coding now will save you heartbreak.