Синтаксис:
Используется javascript
var rotSpeed : float = 30; // скорость поворота орудий
//ткуйщий угол поворота орудий
var thisRotation : float = 0;
function Update () {
// сведение передних групп туреллей клавишей E,Q
if(transform.name == "FrontCannon"){
if (Input.GetKey (KeyCode.E)){
if(thisRotation > -110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.Q)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
}
// сведение задних групп туреллей клавишей E,Q.
if(transform.name == "BackCannon"){
if (Input.GetKey (KeyCode.Q)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.E)) {
if(thisRotation > -110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
}
// поворот передних групп A,D
if(transform.name == "FrontCannon"){
if (Input.GetKey (KeyCode.A)) {
if(thisRotation > -110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.D)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
}
// поворот задних групп A,D
if(transform.name == "BackCannon"){
if (Input.GetKey (KeyCode.A)){
if(thisRotation > -110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.D)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
}
}
//ткуйщий угол поворота орудий
var thisRotation : float = 0;
function Update () {
// сведение передних групп туреллей клавишей E,Q
if(transform.name == "FrontCannon"){
if (Input.GetKey (KeyCode.E)){
if(thisRotation > -110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.Q)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
}
// сведение задних групп туреллей клавишей E,Q.
if(transform.name == "BackCannon"){
if (Input.GetKey (KeyCode.Q)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.E)) {
if(thisRotation > -110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
}
// поворот передних групп A,D
if(transform.name == "FrontCannon"){
if (Input.GetKey (KeyCode.A)) {
if(thisRotation > -110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.D)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
}
// поворот задних групп A,D
if(transform.name == "BackCannon"){
if (Input.GetKey (KeyCode.A)){
if(thisRotation > -110) {
transform.Rotate(Vector3(0, rotSpeed * Time.deltaTime, 0));
thisRotation -= rotSpeed * Time.deltaTime;
}
}
if (Input.GetKey (KeyCode.D)) {
if(thisRotation < 110) {
transform.Rotate(Vector3(0, -rotSpeed * Time.deltaTime, 0));
thisRotation += rotSpeed * Time.deltaTime;
}
}
}
}
Скрипт поворачивает орудийные башни на корабле. Башни делятся на передние"FrontCannon" и задние "BackCannon". клавиши QE сводят башни. клавиши AD поворачивают башни синхронно. Проблема в ограничении угла поворота. Если управлять только одной группой клавиш то все работает - башня поворачивается на определенный максимальный угол и останавливается но если перейти на управление другой группой клавиш то башня продолжает движение.
Как сделать что бы при управлении двумя группами клавиш действовало ограничение поворота?