This repository has been archived on 2020-08-22. You can view files and clone it, but cannot push or open issues or pull requests.
flutter-unity-view-widget/example/unity/DemoApp/Assets/Rotate.cs

45 lines
1.2 KiB
C#

using System;
using UnityEngine;
using UnityEngine.EventSystems;
public class Rotate : MonoBehaviour, IEventSystemHandler
{
[SerializeField]
Vector3 RotateAmount;
// Start is called before the first frame update
void Start()
{
RotateAmount = new Vector3(0, 0, 0);
}
// Update is called once per frame
void Update()
{
gameObject.transform.Rotate(RotateAmount * Time.deltaTime * 10);
for (int i = 0; i < Input.touchCount; ++i)
{
if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
{
var hit = new RaycastHit();
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray, out hit))
{
// This method is used to send data to Flutter
UnityMessageManager.Instance.SendMessageToFlutter("The cube feels touched.");
}
}
}
}
// This method is called from Flutter
public void SetRotationSpeed(String message)
{
float value = float.Parse(message);
RotateAmount = new Vector3(value, value, value);
}
}