[C#] How to position a gameobject using double type numbers?
I need to get the previous gameobject in the list, however I have found that I cannot add anything that are not ints. What is the workaround this? How Can I increase an objects position in c# by 0.64 instead of 1?
All methods regarding positioning or moving gameObjects take floats as parameters. Please show some code.
Its in this line. I cannot move it by 0.7 or any 0.something, only by 1 $$anonymous$$imum.
thisObject.transform.position = array_tiles[f].transform.position + new Vector3(0.7,0,0);
public void spawntiles() {
for (int i = 0; i < int_tile_spawnrate; i++)
{
int f = i - 1;
Vector3 previous_tile_location;
GameObject thisObject;
// Transform tform_thisObject = thisObject.transform.x;
if (i == 0)
{
thisObject = Instantiate(Tiles) as GameObject;
array_tiles.Add(thisObject);
thisObject.transform.position = GameCamera.ScreenToWorldPoint(screenPosition);
}
if (i != 0)
{
thisObject = Instantiate(Tiles) as GameObject;
array_tiles.Add(thisObject);
thisObject.transform.position = array_tiles[f].transform.position + new Vector3(0.7,0,0);
// previous_tile_location = array_tiles[f].transform.position + array_tiles[f].GetComponent<Collider>().bounds.size;
// var vector_previous_tile_position =array_tiles[f].transform.position;
// vector_previous_tile_position.x = vector_previous_tile_position + Tiles.;
}
}
}
thisObject.transform.position = array_tiles[f].transform.position + new Vector3(0.7,0,0);
This line doesn't even compile for me, because it complains that the Vector3 constructor takes only floats as parameters.
Try this ins$$anonymous$$d:
new Vector3(0.7f, 0f, 0f);
Answer by LucianoMacaDonati · Oct 31, 2016 at 11:11 PM
I think you're misunderstanding array (or lists) indexes (Integers) and plain floating point numbers.
transform.position += Vector3.Lerp(trasnform.position, myList[ index ], Time.deltatime * speed);
Like @doublemax said, if you show some code we would be able to help you better ins$$anonymous$$d of guessing what the problem is.
Thank you for answering. I have posted code in @doublemax code.
Hello @upariver,
I believe what you're looking for is to set a transform's position. You can't set the position member's individually (transform.position.x = 5). What you can do, is set the whole position Vector3:
transform.position = new Vector3( 0.0f , 5.36f, 3.14f);
Since a Vector3 is conformed of 3 floats, you must add those 'f' to the end. I see you're trying to use this in array_tiles[f] where you should be using array_tiles[i] ins$$anonymous$$d (since i is the index of your forloop).
I recommend starting really slow on simple operations before jumping into for-loops and iterations. Try moving a single transform every frame, or scaling something up and then try doing it yo many objects. Good luck !
Your answer
Follow this Question
Related Questions
How to get type double to vector3? 0 Answers
What are the benefits of 1 unit per meter? 2 Answers
Problem operating with doubles 1 Answer
Why is my list bigger than it should be? 2 Answers
Recursive reference within a list 2 Answers