Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created May 3, 2018 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/fb70b02425276fecd2b13c9f029c1ca5 to your computer and use it in GitHub Desktop.
Save todorok1/fb70b02425276fecd2b13c9f029c1ca5 to your computer and use it in GitHub Desktop.
Unityチュートリアル・早送りボタンの機能を実装するスクリプト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FastForward : MonoBehaviour {
// 早送りのスピード
[SerializeField]
float scale = 2.0f;
// ボタン押下フラグ
bool isButtonPressed = false;
void Start(){
}
void Update(){
// スケールの適用
CheckTimeScale();
}
void CheckTimeScale(){
// スケール格納用ローカル変数
float newTimeScale = 1.0f;
if (isButtonPressed){
// ボタンが押されている間は早送りする
newTimeScale = scale;
}
// Unity世界の時間にスケールを適用
Time.timeScale = newTimeScale;
}
public void OnPressedFastButton(){
// 早送りボタンが押されたタイミングでフラグをtrueにする
isButtonPressed = true;
}
public void OnReleasedFastButton(){
// 早送りボタンが押されたタイミングでフラグをfalseにする
isButtonPressed = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment