- Home /
How do you position an object relative to the camera?
I'm quite new to Unity and scripting in general, so this could be a really stupid question, but how would you position an object such that it is just in front of the camera and will move with you as you move? I've tried this, but it won't compile..
public GameObject woodBox;
void Start () {
woodBox = GameObject.Find ("Box1");
}
void Update () {
if (Input.GetButtonDown("Fire2"))
woodBox.transform.parent = camera.transform;
transform.localPosition = Vector3(1,0,1);
}
I set up the variable woodBox
so that I could identify a game object I was using that I didn't know the name of. So far, the compiler throws up this, for the last line of code:
error CS0119: Expression denotes a
type', where a variable',
value' or method group' was expected
Any help would be appreciated :)
Add new
in front of Vector3
: = new Vector3(...
.
The rule is borrowed from Java, where a $$anonymous$$m of psychologists decided that constantly typing "new" would give you a good feeling as you worked :-)
Removed my answer - didn't read the question well enough. What @Owen-Reynolds said. The C# syntax is new Vector3(1, 0, 1)
.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Camera to follow the player in the form of radius 1 Answer
Problems implementing a 3rd person static camera 0 Answers
Switching cameras Script error 0 Answers