It follows the path of unity so that the object point position automatically moves

Automatic animation can do, as long as the path set point on it,

 

    private Transform[] ways1;//路径点的位置
    public Transform  tagret;//移动的物体
    private int index1;

 private void Start()
    {
        ways1 = JieLine.instance.LuJing;
        index1 = 0;
        tagret.transform.gameObject.SetActive(false);
    }
   public void MoveToway1()
    {
        if (index1 > ways1.Length - 1) { return; }
        tagret.localPosition = Vector3.MoveTowards(tagret.localPosition, ways1[index1].localPosition, speed * Time.deltaTime);
        if (Vector2.Distance(ways1[index1].localPosition, tagret.localPosition) < 0.01f)
        {
            index1++;

            if (index1 == ways1.Length)
            {
                tagret.localPosition = ways1[index1 - 1].localPosition;    
                
            }           
        }
    }

 

Guess you like

Origin www.cnblogs.com/qq2351194611/p/11591927.html