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.
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...
Thank you for that. The small things like that always screw me up. I am programming 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?
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.
Thank you for that. The small things like that always screw me up. I am programming 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?
– doomprodigyFixed 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.
– doomprodigy