【问题标题】:Moving and teleporting an object in the x direction forever永远沿 x 方向移动和传送对象
【发布时间】:2020-09-30 22:57:42
【问题描述】:

所以我遇到了这个困扰我一段时间的问题,我需要让 3 个游戏对象以基本设定速度的 % 速度移动。那部分很容易。现在的问题是我无法让它移动到设定的位置,然后传送到我面前并继续, 非常感谢您的帮助!

What I'm going for

Current code

更新功能

    void Update()
{
    //suuuuper bad implemantation
    float newPos = Mathf.Repeat(Time.time * globalspeed, 20);
    Ground1.transform.position = startpos + new Vector2(reset, upPos1) * newPos * Ground1Speed;
    Ground2.transform.position = startpos + new Vector2(reset, upPos2) * newPos  * Ground2Speed;
    Ground3.transform.position = startpos + new Vector2(reset, upPos3) * newPos * Ground3Speed;

}

【问题讨论】:

    标签: c# unity3d game-physics parallax


    【解决方案1】:

    我不确定我是否理解您想要的,但如果我是对的,您希望 3 个游戏对象在地面上移动(如驾驶汽车)并在它们到达终点时消失,然后出现在开头定位并再次无限循环移动。如果我是对的,你应该试试这个:

    public float objectSpeed;
    
    void update()
    {
        MoveObject();
    }
    
    void MoveObject()
    {
    
        objectSpeed = 20; //Set the object speed
        
        if (transform.position.x >= 120) //Set the position to where you want your object to disappear
        {
            disapper(gameObject);
        }
    
        if (transform.position.x >= 300) //This position is related to when the object will appear again in the start position
        {
            appear(gameObject);
        }
        
        void disappear()
        {
            transform.Find(gameObject).GetComponent<MeshRenderer>().enabled = false;
        }
    
        void appear()
        {
            transform.Find(gameObject).GetComponent<MeshRenderer>().enabled = true;
        }
    } // Drag this script to 3 of the game object you want them to move. This code is no tested but should work fine.
    

    【讨论】:

      猜你喜欢
      • 2017-01-11
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多