Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 doomprodigy · Dec 13, 2011 at 04:49 AM · vector3object position

Object position x = to another objects x position.

I have looked around an I am still a bit new to using "position" as I have not really needed to use it before in things I have coded.

I am trying to make the objects x position = to another objects x position.

Here is my scrpt C#

 using UnityEngine;
 using System.Collections;
 
 public class InLine : MonoBehaviour {
 
     public GameObject Player;
     public GameObject Me;
 
     void Update () {
         Player.position = new Vector3 (transform.position.x, transform.position.y, transform.position.z);
         Me.position = new Vector3 (Player.x, transform.position.y, transform.position.z);
         }
     }

I get the issues: Vector 3 issues float, float, float. Gameobject has no definition for position and GameObject has no definition for x or extensions of w.e something along those lines.

Any help I would be very grateful.

Thank you,

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
1
Best Answer

Answer by jahroy · Dec 13, 2011 at 05:05 AM

Position is a member (or property) of the Transform class.

The variable x is a member (or property) of a transform's position.

To reference the x-value of the position of a transform, you do this:

var otherThing : GameObject;

function Update () { gameObject.transform.position.x = otherThing.transform.position.x; }

Or something like that...

In this case gameObject.transform.position means the position of the transform of the game object that this script is attached to. In other words, you shouldn't need the variable named Me.

I usually work with Transforms rather than GameObjects, but I think it works like that.

Also, variable names should begin with lowercase letters. Capital letters are used for classes, functions, namespaces, etc...

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 doomprodigy · Dec 13, 2011 at 05:17 AM 0
Share

Thank you for that. The small things like that always screw me up. I am program$$anonymous$$g in C# thus why I think I got this error Assets/InLine.cs(10,30): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable Any help with that?

avatar image jahroy · Dec 13, 2011 at 05:38 AM 0
Share

It sounds like the compiler is just confused because (according to what it knows) you're treating members like functions and/or vice versa.

I'm not sure if you're asking me about a separate compiler error or not.

If you are, your best bet is to include the code from your file where the error occurs.

The compiler errors will usually point you towards a specific line number in one of your scripts.

The above error message indicates that something is wrong on line 10 of a file named InLine.cs.

EDIT:

I just took a closer look at your code.

That error message is a result of the fact that you declare the variable named $$anonymous$$e to be a GameObject. You then refer to $$anonymous$$e.position.

This is confusing the compiler because a GameObject does not have a field named position. This is an error. A GameObject has a transform (which has a position).

I guess getting that idea across was the desired goal of my answer.

avatar image doomprodigy · Dec 13, 2011 at 07:02 AM 0
Share

Fixed it all Cheers mate what you said helped me work out my problem. It was more to do with my converting from JS to C# than what you wrote, Cheers for the understanding though.

avatar image
0

Answer by RockingGameDeveloper · Dec 01, 2019 at 07:40 PM

Thank you to the person who knows the difference between JavaScript and C#!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Quaternion to Vector3,Player transform in vector3? 1 Answer

Slow falling when using Rigidbody set velocity as playercontroller 0 Answers

Rotate a Vector3 (linear force to fly like a plane) with mouse position 0 Answers

C# Smoothing Out transform.Translate 0 Answers

Slerp to make the right/left side face another object 2 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