using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class BGColorChange : MonoBehaviour {
public Image BG;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.acceleration.z > 0.9f)
{
BG.color = Color.black;
}
else
{
BG.color = Color.white;
}
}
}
using System.Collections;
using UnityEngine.UI;
public class BGColorChange : MonoBehaviour {
public Image BG;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Input.acceleration.z > 0.9f)
{
BG.color = Color.black;
}
else
{
BG.color = Color.white;
}
}
}
本文介绍了一个Unity3d脚本,通过监听设备的重力感应,当加速度z轴超过0.9时,将背景颜色更改为黑色,否则为白色。这个简单示例展示了如何结合物理感应和UI元素交互。
2158

被折叠的 条评论
为什么被折叠?



