コード例 #1
0
    void ManageBehabiour()
    {
        switch (currentState)
        {
        case WalkBetweenBoundsSM.WAITING:
            t += Time.deltaTime;
            if (t >= waitingTime)
            {
                currentState = WalkBetweenBoundsSM.WALKING;
                t           -= waitingTime;
            }
            break;

        case WalkBetweenBoundsSM.WALKING:
            _rigidbody.velocity = new Vector3(dir * walkSpeed * Time.deltaTime, _rigidbody.velocity.y, 0f);

            if (dir < 0 && isFacingRight)
            {
                Flip();
            }
            else if (dir > 0 && !isFacingRight)
            {
                Flip();
            }
            break;
        }
    }
コード例 #2
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.layer == 13)
     {
         dir *= -1;
         _rigidbody.velocity = new Vector3(0, _rigidbody.velocity.y, 0f);
         currentState        = WalkBetweenBoundsSM.WAITING;
     }
 }