unity 脚本问题 可移动平台

脚本似乎无法进入else if(transform.position.x == _Startpos.x)板块


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MovingPlatform : MonoBehaviour
{
    public Vector3 finishaPos = Vector3.zero;
    public float speed = 0.5f;
    private Vector3 _nowPos;
    private Vector3 _Startpos;
    private int _direction;
    // Start is called before the first frame update
    void Start()
    {
        _Startpos = transform.position;
         _nowPos =  _Startpos;
    }

    // Update is called once per frame
    void Update()
    {
        float deltaX = speed * _direction * Time.deltaTime;
        _nowPos = new Vector3(deltaX+_nowPos.x,_Startpos.y,_Startpos.z);
        transform.position = _nowPos;

        if(transform.position.x == finishaPos.x){
            _direction = -1;
        }
        else if(transform.position.x == _Startpos.x)
        {
            _direction = 1;
        }
        else{
            
        }
        if(_direction==-1){
            Debug.Log(_direction);
        }
    }
}

参考GPT和自己的思路:根据你提供的代码,else if(transform.position.x == _Startpos.x)板块可以正常进入。由于你的问题不够具体,我无法判断你遇到的具体问题是什么。你可以提供更多的上下文信息,以便我更好地帮助你解决问题。