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 /
  • Help Room /
avatar image
0
Question by Aaron Lieberfreund · Nov 23, 2015 at 06:05 AM · xyz

Hi, How can you create a box whereby you can change xz values of a GameObject in runtime?

Hi, How can you create a box whereby you can change xz values of a GameObject in runtime?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fredz0004 · Nov 23, 2015 at 07:34 AM

I don't see any code, so I would imagine you are a beginner. No worries. You will need to create a simple script, and attach it to the cube. In the inspector you would just modify those value as you wish. The reason why this is in update() is because it is called on every frame.

The position of a game object is accessed through "Transform".

http://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html http://docs.unity3d.com/ScriptReference/Transform.html

using UnityEngine; using System.Collections;

public class Cube : MonoBehaviour {

 // Variables
 public float positionX;
 public float positionY;
 public float positionZ;
 
 void Update() {
     gameObject.transform.position(positionX, positionY, positionZ);
 }

}

I hope this helps!

Edit 1: Ok what you are looking for then is GUI class. You would probably need a TextArea or a TextField for entering text. And then maybe a button if you want it to only send when you press a button.

http://docs.unity3d.com/ScriptReference/GUI.html

A sample script is below:

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     public float xPositionPlayer;
     public string xPositionString;
     void OnGUI() {
         xPositionString = GUI.TextField(new Rect(10, 10, 200, 20), xPositionString, 25);

     if (GUI.Button(new Rect(10, 10, 50, 30), "New X position"))
         Debug.Log("Send X parameter to the player");
         xPositionPlayer = float.Parse(xPositionString);
     }
 }

Note that the TextField is a string, and thus why it needs to be parsed to a float. Just pass the xPositionPlayer to player, and also you might need to play around with the Rect values. Also FYI if you really need to get good with GUI stuff there are several tutorials on YT.

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 Aaron Lieberfreund · Nov 23, 2015 at 07:40 AM

Sorry, let me explain it better. I don't want to modify the xyz values. What I want to do is create a box in the game view whereby the player can enter a value whilst playing and go to that coordinate.

Comment
Add comment · Show 3 · 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 fredz0004 · Nov 23, 2015 at 11:13 PM 0
Share

What exactly do you mean by "creating a box"? Are you talking about cubes, a plane? You need to be more specific. Any gameObject has the transform.position by the way. I think you are talking about having a text input on the screen for the player to move around the world. But I'm not sure your descriptions are vague.

avatar image Aaron Lieberfreund · Nov 23, 2015 at 11:48 PM 0
Share

Yes. A text input on the screen whereby a player can modify the transform values.

avatar image fredz0004 · Nov 24, 2015 at 04:55 AM 0
Share

I updated my answer, for future reference just make a comment ins$$anonymous$$d of an answer. And try to be very descriptive on your question, I know sometimes is hard to describe things when you are a beginner.

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

35 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 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

If collided have ObjectA follow ontop of ObjectB 2 Answers

Attaching GameObject to the XYZ Directional cursor of that object? 0 Answers

How do I make everything smaller? 1 Answer

How to use input field value in scripting? 1 Answer

How can I add Z axis on input manager? 0 Answers


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