-
I want to do this…
I want to change 2d image a to b when I tilt my smartphone.
I just start Unity in this month so I don’t know how to solve this problem.
Please help me. Thank you.
-
I tried this
With two objects in hand.
①for rotated
②for trigger when this object collision -
Problem
It does not print “hit!!!” despite the collision.
I write code following this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColliderManager : MonoBehaviour
{
private Gyroscope m_gyro;
// Start is called before the first frame update
void Start()
{
Input.gyro.enabled = true;
}
void Update()
{
m_gyro = Input.gyro;
transform.rotation = m_gyro.attitude;
}
private void OnGUI()
{
var rect1 = new Rect(30, 30, 600, 50);
var rect2 = new Rect(30, 60, 600, 50);
GUI.skin.label.fontSize = 30;
GUI.Label(rect1, "attitude=" + m_gyro.attitude);
GUI.Label(rect2, "rotationRate=" + m_gyro.rotationRate);
}
private void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.tag == "Cube2")
{
print("hit!!!");
}
}
}
I refer to following this sites.