- Home /
Query Code Containing Issue
Hi, I am a game developer and I am here to ask a query code containing an issue. I am working on android game & searching for helpful android developer forum. I have searched a lot of forums but issue remains the same. I hope any tech developer can help me over here in resolving the issue.
using UnityEngine; using System.Collections;
public class Exam : MonoBehaviour { void Start () { transform.position.x = 10; } }
EDIT: Haha totally didn't dawn on me that you were trying to set a single vector of a transform. @hexagonius has the right answer.
Answer by hexagonius · Feb 17, 2017 at 10:36 AM
transform.position is a property returning a Vector3, which is a struct. As with structs, that get passed by value, not reference, you need to get the value, change it and most importantly, assign it back.
using UnityEngine;
using System.Collections;
public class Exam : MonoBehaviour {
void Start () {
Vector3 newPosition = transform.position;
newPosition.x = 10;
transform.position = newPosition;
}
}
Your answer

Follow this Question
Related Questions
How do I Optimize Resources/Unity_Builtin_Extra 2 Answers
Social.localUser.userName == "Lerpz" 1 Answer
Authentication is required you need to sign in google account? 2 Answers
How to include obb extension files in Google play developer console 0 Answers
I want to ask about Android developers 0 Answers