【问题标题】:How do I get one game objects x position to equal another objects x position? (2D Unity Game)如何让一个游戏对象 x 位置等于另一个对象 x 位置? (二维统一游戏)
【发布时间】:2020-07-02 18:56:55
【问题描述】:

我有 2 个游戏对象,一个在 X 位置,一个在同一个位置 x位置取决于。所以 Object1 有一个设置的 x 位置,然后 object2 应该找到 Object1 的 x 位置以正确排列它。

这是我尝试过的,但它不起作用:

 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;
    }

【问题讨论】:

  • this 回答你的问题了吗?

标签: c# ios unity3d


【解决方案1】:

您可以将第一个传递给第二个。 然后在Update() 方法中使用transform.Translate() 将其位置更改为其他位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多