[英]How do I get one game objects x position to equal another objects x position? (2D Unity Game)
I have 2 game objects, one that is in a set X position and one that I was to spawn in the same x-position depending on.我有 2 个游戏对象,一个在设置的 X 位置,另一个在相同的 x 位置生成,具体取决于。 So Object1 has a set x position then object2 should find Object1's x-position to line it up properly.所以对象 1 有一个设置的 x 位置,然后对象 2 应该找到对象 1 的 x 位置以正确排列它。
Here is what I have tried, and it is not working:这是我尝试过的,但它不起作用:
public GameObject LeftSpawn;
public GameObject MiddleSpawn;
public GameObject RightSpawn;
public GameObject EnemyLeftSpawn;
public GameObject EnemyMiddleSpawn;
public GameObject EnemyRightSpawn;
public GameObject LeftButton;
public GameObject MiddleButton;
public GameObject RightButton;
private float pos1;
// Start is called before the first frame update
void Start()
{
pos1 = GameObject.Find("Left Button").transform.position.x;
GameObject.Find("Left Enemy Spawn Point").transform.position.x = pos1;
}
You can pass the first one to the second one.您可以将第一个传递给第二个。 then in the Update()
method use the transform.Translate()
to change it's position to the other ones.然后在Update()
方法中使用transform.Translate()
将其位置更改为其他位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.