Я создал скрипт для вращения куба и еще один скрипт для нажатия кнопки.
Теперь, как я могу заставить этот куб вращаться при нажатии этой кнопки.
Код для кнопки:
Код: Выделить всё
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ButtonInput1 : MonoBehaviour {
Button button = null;
void Rotate()
{
a++;
button.onClick.AddListener(delegate() { PlayerController.CubeRotate ();});
}
}
Код: Выделить всё
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
int a = 1;
public void CubeRotate() {
if (Input.GetButton("Button1")) {
a++;
//transform.Rotate ( new Vector3(15,30,45) * Time.deltaTime);
}
if (a % 2 == 0) {
transform.Rotate ( new Vector3(15,30,45) * Time.deltaTime);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/310 ... in-unity3d