Created
November 17, 2018 08:17
-
-
Save hyoune/34969e15bbff19c2f8461f2e67bf3ee8 to your computer and use it in GitHub Desktop.
main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using Live2D.Cubism.Core; | |
using Live2D.Cubism.Framework; | |
public class main3 : MonoBehaviour | |
{ | |
private CubismModel _model; | |
float[] list = new float[4]; | |
float[] list2 = new float[4]; | |
int count = 0; | |
float sum; | |
float sum2; | |
float avg; | |
float avg2; | |
bool a = false; | |
private Vector3 Acceleration; | |
private Vector3 preAcceleration; | |
float DotProduct; | |
public static int ShakeCount; | |
float timeElapsed; | |
bool TimeCount = false; | |
private Animator animator; | |
int hashRandom = Animator.StringToHash("random"); | |
private void Start() | |
{ | |
_model = this.FindCubismModel(); | |
animator = GetComponent<Animator>(); | |
Input.gyro.enabled = true; | |
var dir = Vector3.zero; | |
dir.x = 0; | |
dir.y = 0; | |
} | |
private void LateUpdate() | |
{ | |
animator.SetInteger(hashRandom, Random.Range(0, 2)); | |
var dir = Vector3.zero; | |
if (count < 4) | |
{ | |
dir.x = Input.acceleration.x; | |
dir.y = Input.acceleration.z; | |
list[count] = dir.x; | |
list2[count] = dir.y; | |
count++; | |
} | |
else | |
{ | |
count = 0; | |
a = true; | |
} | |
if (a == true) | |
{ | |
sum = list[1] + list[2] + list[3]; | |
sum2 = list2[1] + list2[2] + list2[3]; | |
avg = sum / 3 ; | |
avg2 = sum2 / 3; | |
//パラメータの更新 | |
var value01 = avg * 30; | |
var value02 = avg2 * 20; | |
var parameter01 = _model.Parameters[0]; | |
var parameter02 = _model.Parameters[1]; | |
parameter01.Value = -value01; | |
parameter02.Value = -value02; | |
sum = 0; | |
sum2 = 0; | |
} | |
// タップ処理 | |
if (Input.GetMouseButtonDown(0)) | |
{ | |
animator.SetBool("tap", true); | |
Debug.Log("タップ・クリック"); | |
} | |
if (Input.GetMouseButtonUp(0)) | |
{ | |
animator.SetBool("tap", false); | |
} | |
// シェイク処理 | |
preAcceleration = Acceleration; | |
Acceleration = Input.acceleration; | |
DotProduct = Vector3.Dot(Acceleration, preAcceleration); | |
if (DotProduct < 0) | |
{ | |
ShakeCount++; | |
Debug.Log(ShakeCount); | |
TimeCount = true; | |
} | |
if(TimeCount == true) | |
{ | |
timeElapsed += Time.deltaTime; | |
if (ShakeCount >= 5) | |
{ | |
animator.SetBool("shake", true); | |
ShakeCount = 0; | |
} | |
if (timeElapsed >= 3) | |
{ | |
TimeCount = false; | |
ShakeCount = 0; | |
DotProduct = 0; | |
timeElapsed = 0; | |
} | |
} | |
else | |
{ | |
animator.SetBool("shake", false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment