Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
-1
Question by Ninjaoboy · Jun 13, 2011 at 08:09 PM · vector3directionxyz

a variable that allows you to choose either x,y, or z?

I have a script that makes the character move 1 space in the Z direction, when you press "f" by a door it will move you inside, but i want it to be a variable because then i can attach it to building with a different direction door. so basicly how do i make a variable that you either fill in a letter or has three options... each a letter?

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by burnumd · Jun 13, 2011 at 08:31 PM

Add a Vector3 public variable to the script. When you move the player, move it by that amount.

So, if right now you're doing something like

 playerTransform.position.z += 1;

Instead do

 var playerMoveAmount : Vector3;

 function MyTrigger ()
 {
     playerTransform.position += playerMoveAmount;
 }

I'm making a lot of assumptions because you didn't post any code, but you'd make sure MyTrigger is called whenever the event that causes the player to move happens.

Comment
Add comment · 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
0

Answer by Anxo · Jun 13, 2011 at 08:15 PM

I think your talking about a Vector3? which is a position in space and allows you to store X,Y,Z but the way you are using it sounds like you might be better off using 3 different variables.

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 Ninjaoboy · Jun 13, 2011 at 08:21 PM 0
Share

what i mean is, and i have thought about your way, is i have something like Player.transform.position.z += 1;

but ins$$anonymous$$d of z i want to have a variable so i can change it without ruining the script on different doors, do you understand what i mean, i can do it like you said but that is more room for error with so many number, all the decimals and what not.

avatar image Anxo · Jun 13, 2011 at 08:34 PM 0
Share

sorry, I am not quite sure what the problem is. Could you explain a little more .

avatar image
0

Answer by Chrisg · Jun 13, 2011 at 11:43 PM

Do you mean you want the script to be robust, and able to be placed in a 3d world regardless of door rotation, so the character can "use" the door and be placed on the otherside regardless of if that's 1 in the z, 5 in the z, or 5 in the y?

 var moveDist : int = 5;
 
 function OnMouse()
 {
 //collision check - make sure there's something there, not empy space
 var hit = physics.raycast(transform.position, vector3.forward*moveDist, hit);
 //make sure it's the door, and not some kind of manatee
 if(hit.tag = "Door")
 //Translate("jump to") to a position that is forward along the current rotation of the //current object(ie, z-axis), by an amount equal to moveDist(vector3.forward is 0,0,1)
 transform.Translate(vector3.forward * moveDist);
 }

Might have syntax wrong, did it from my head, but a quick doc check will sort that out. moveDist will be avaliable via the editor, and you can change it like any other object property - if your doors are six units thick, set it to 6. Apply the script to the camera or the player object.

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Get rotation from a vector direction. 1 Answer

Unity 5 C# - MoveTowards is only moving in a single direction 1 Answer

Difference between Vector.up and transform.up 2 Answers

Fanning out projectiles depending on direction 1 Answer

Declaring Vector in inspector for directional movement 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