Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Robomaster · Jan 12, 2014 at 09:47 PM · positiongameobjectsvectorchanging

Changing a GameObjects Position

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sparkzbarca · Jan 12, 2014 at 09:53 PM 0
Share

the easiest would be to change the positions on level load

basically something like

bool LoadingScene1;

if(LoadingScene1) { transform.postioin = ...; }

HOWEVER THIS IS FOR DYNA$$anonymous$$ICALLY GENERATED STUFF

if you for example place objects in the scene in the unity editor they will have that position. if you start a new scene and place stuff and load that scene it'll of course place those objects where those are.

but yea you just start the load process and at somepoint do a startcoroutine or call a function or change a bool or something and start changing out values. Does that make sense?

avatar image Robomaster sparkzbarca · Jan 12, 2014 at 10:13 PM 0
Share

Sorry no I'm not completely sure what you mean. The game is like a board game type style so i want each hero to start in a specific place on the board. And since the user picks his 5 heroes those heroes get saved to and array. i want all that data to get saved and carried over to the next level when the user starts the game (I'm using dontdestroyonload), But since i dont know what heroes the user will pick, only the variable names that the heroes will get saved to, i wanted to know if there was something to say This gameobject/variable is suppose to appear here at the beginning of a scene.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Jan 13, 2014 at 12:07 AM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Robomaster · Jan 14, 2014 at 05:15 PM 0
Share

WOW thank you this was very informative and quite helpful, I am very appreciative and this is going to help my program so much! So I'm guessing in the script that pertains to a certain hero the startpos variable would be something like, startpos = Vector3 (X,Y,Z); And then transform.postion = startpos; Would that be correct?

avatar image sparkzbarca · Jan 15, 2014 at 03:37 AM 0
Share

yep thats how it works. post if your having any issues. I have some weapon scripts as well that show inheritance where you go from a turret to a ballistic/energy turret to a torpedo turret so you have the torpedo turret which inherits from ballistic turret which inherits from turret base to show how inheritance progression works.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Empty Parent GameObject Moving with Child 1 Answer

translate 2 Answers

Random Range Position 2 Answers

How to make cubes between 2 point and stick them together? 0 Answers

Two Firing points, Vectors 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges