Eda minigame but new branch
This commit is contained in:
30
Assets/Scripts/GyroPlatformController.cs
Normal file
30
Assets/Scripts/GyroPlatformController.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GyroPlatformController : MonoBehaviour
|
||||
{
|
||||
public Rigidbody ball;
|
||||
public float forceStrength = 30f;
|
||||
public float dampingPerSecond = 0.9f;
|
||||
void Start()
|
||||
{
|
||||
if (SystemInfo.supportsGyroscope)
|
||||
{
|
||||
Input.gyro.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (ball == null) return;
|
||||
|
||||
Vector3 g = Input.gyro.gravity;
|
||||
|
||||
Vector3 force = new Vector3(g.x, 0f, g.y);
|
||||
|
||||
ball.AddForce(force * forceStrength, ForceMode.Acceleration);
|
||||
|
||||
float frameDamping = Mathf.Pow(dampingPerSecond, Time.deltaTime);
|
||||
|
||||
ball.linearVelocity *= frameDamping;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user