функция возвращает ложь, когда должна вернуть истину - PullRequest
0 голосов
/ 14 мая 2018

Я пытаюсь создать базовую фигуру в Unity, которая превращается в определенные ограничения с помощью ввода с клавиатуры. Однако, когда я пытаюсь повернуть направо с крайней левой стороны. Кажется, что вход не вызывается из-за функции, не возвращающей true, когда, насколько я понимаю, должен.

https://i.stack.imgur.com/5Aldd.png

Кто-нибудь знает, почему это не возвращает истину? Вот остальная часть скрипта, если необходимо:

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

public class ControlScript : MonoBehaviour {
public Rigidbody shipRig;
public int rotationSpeed = 1;
public int retRotationSpeed = 1;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    Rigidbody tempShipRig = GetComponent<Rigidbody>();
    Vector3 shipEuler = shipRig.rotation.eulerAngles;

    //up input
    if (Input.GetKey(KeyCode.W) && CheckBounds(shipEuler.x, 0, 25) || 
Input.GetKey(KeyCode.W) && CheckBounds(shipEuler.x, 335, 360))
    {
        shipEuler.x = shipEuler.x + (-rotationSpeed * Time.deltaTime);
    }
    //down input
    else if (Input.GetKey(KeyCode.S) && CheckBounds(shipEuler.x, 0, 25) || 
Input.GetKey(KeyCode.S) && CheckBounds(shipEuler.x, 335, 360))
    {
        shipEuler.x = shipEuler.x + (rotationSpeed * Time.deltaTime);
    }
    else if(shipEuler.x !=0) //idle return to center
    {
        if(shipEuler.x < 180)
        {
            shipEuler.x = shipEuler.x - (retRotationSpeed * Time.deltaTime);
            if(shipEuler.x < 0)
            {
                shipEuler.x = 0;
            }
        }
        if (shipEuler.x > 180)
        {
            shipEuler.x = shipEuler.x + (retRotationSpeed * Time.deltaTime);
            if (shipEuler.x > 360)
            {
                shipEuler.x = 0;
            }
        }
    }
    //left input
    if (Input.GetKey(KeyCode.A) && CheckBounds(shipEuler.z, 0, 45) || 
Input.GetKey(KeyCode.A) && CheckBounds(shipEuler.z, 315, 360))
    {
        shipEuler.z = shipEuler.z + (rotationSpeed * Time.deltaTime);
    }
    //right input
    else if (Input.GetKey(KeyCode.D) && CheckBounds(shipEuler.z, 0, 45) || 
Input.GetKey(KeyCode.D) && CheckBounds(shipEuler.z, 315, 360))
    {
        shipEuler.z = shipEuler.z + (-rotationSpeed * Time.deltaTime);
    }


    if (shipEuler.x > 25 && shipEuler.x < 335) //fixes the rotation getting stuck when they pass over constraints
    {
        if(shipEuler.x < 180)
        {
            shipEuler.x = 25;
        }
        if(shipEuler.x > 180)
        {
            shipEuler.x = 335;
        }
    }
    if(shipEuler.z > 45 && shipEuler.z < 315)
    {
        if(shipEuler.z < 180)
        {
            shipEuler.z = 45;
        }
        if(shipEuler.z > 180)
        {
            shipEuler.z = 315;
        }
    }

    shipRig.rotation = Quaternion.Euler(shipEuler);
    shipRig = tempShipRig;

    Debug.Log(shipEuler);
}

bool CheckBounds (float orNr, float min, float max) //returns true if numbers are within constraints
{
    return (orNr <= max && orNr >= min);
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...