Unity(C#)における質問です。Time.timeScale=0で時間を止めた後、Update内でキー入力を取得次第Time.timeScale=1を実行したいのですが、Update内なのに実行されなくて原因がわからず困っています。
###スクリプト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player : MonoBehaviour
{
public float speed;
public GameObject Keepcanvas;
private Rigidbody2D rb;
private bool cool=false;//動けなくさせるシステム
public GameObject invent;
public Image isr;
private bool inventcool;
void Start()
{
rb= GetComponent<Rigidbody2D>();
velocity = new Vector2(speed, 0);
isr = invent.GetComponent<Image>();
isr.color = new Color(0.675f, 0.675f, 0.675f, 0f);
}
void Update()
{
if (cool == false)//この中は停止可能
{
if (isr.color.a == 0f)//消えてるとき
{
foreach (Transform child in invent.transform)
{
child.transform.localScale = new Vector3(child.transform.localScale.x, 0, child.transform.localScale.z);
}
if ((Input.GetKey("e")) && (inventcool == false))//入力されたら { isr.color = new Color(0.675f, 0.675f, 0.675f, 0.9f); Invoke("Inventcooling", 0.2f); inventcool = true; **Time.timeScale = 0;** foreach (Transform child in invent.transform) { child.transform.localScale = new Vector3(child.transform.localScale.x, 60, child.transform.localScale.z); } } } if ((isr.color.a == 0.9f) && (Input.GetKey("e")) && (inventcool == false))//消えてないときに入力されたら { **Time.timeScale = 1;** isr.color = new Color(0.675f, 0.675f, 0.675f, 0f); Invoke("Inventcooling", 0.2f); inventcool = true; } }
回答1件
あなたの回答
tips
プレビュー