unity游戏Demo——甩鞭子

利用unity的控制手机震动的api,实现的甩鞭子小游戏
这是极其丑陋的游戏界面~~~
游戏画面
这里是脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ak : MonoBehaviour {
    Vector3 oldPos = Vector3.zero;
    Vector3 newPos = Vector3.zero;
    float distance = 0;
    float TARGET = 1;
    float COUNT = 3;
    AudioSource audio;

    // Use this for initialization
    void Start () {
        audio = GetComponent<AudioSource>();
    }
    int count = 0;
    // Update is called once per frame
    void Update () {
        newPos = Input.acceleration;
        distance = Vector3.Distance(oldPos, newPos);
        oldPos = newPos;
        if (distance > TARGET)
        {
            count++;
            if (count == COUNT)
            {
                Handheld.Vibrate();
                audio.Play();
                count = 0;
            }
        }
        else
        {
            count = 0;
        }
    }
}

这里是Demo
百度网盘

展开阅读全文

没有更多推荐了,返回首页