hello guys,
I exploring unity world, and i really trying do a simple thing, but i having a anoiyng result… i trying do the mouse pull the world just so much i press mouse button (sorry my indian english).
Its my code:
void Update () {
if (Input.GetMouseButtonDown (0)) {
vector3_X = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 5.0f));
vector3_Y = Camera.main.transform.position;
}
if (Input.GetMouseButton (0)) {
vector3_Z = Camera,main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 5.0f));
mouseA = Input.mousePosition;
if (string == null) {
Camera.main.transform.position = new Vector3 (vector3_Y.x-(vector3_Z.x - vector3_X.x), 5.0f, vector3_Y.z-(vector3_Z.z - vector3_X.z));
string = “done”;
mouseB = mouseA;
}
if (mouseB != mouseA) {
string = null;
}
}
But, unhappy, the camera vibrate like a crazy. The result of [vector3_Y.x-(vector3_Z.x - vector3_X.x)] and [vector3_Y.z-(vector3_Z.z - vector3_X.z)] always return 2 values for float without move mouse, doint the camera vibrate. Wtf i wrong? O.o?
Thanks a lot.
I already solve it, using transform.translate in place of transform.position.
But i really really knows why unity return 2 values to same float of a vector3. xD If someone knows, pls share with us!
Thanks for the tip position and translate. The only advice i can give you here is not in relation with your question. you can add code using “insert”. Insert is between the media negative pix icon and the disk draft icon. The icon looks like a text letter. Select it and then choose “code”. or you can use [ ] code and the close /code inside[ ]. Is much simple to read your code. And try to indent it.
void Update () {
if (Input.GetMouseButtonDown (0))
{
vector3_X = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 5.0f));
vector3_Y = Camera.main.transform.position;
}
if (Input.GetMouseButton (0))
{
vector3_Z = Camera,main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 5.0f));
mouseA = Input.mousePosition;
if (string == null) {
Camera.main.transform.position = new Vector3 (vector3_Y.x-(vector3_Z.x - vector3_X.x), 5.0f, vector3_Y.z-(vector3_Z.z - vector3_X.z));
string = "done";
mouseB = mouseA;
}
if (mouseB != mouseA) {
string = null;
}
}
So a bracket is missing