前提・実現したいこと
プレイヤーが2秒後に動くスクリプトを書いてみたのですがヒエラルキーで2.0になっているのを確認したのですが動きません
発生している問題・エラーメッセージ
カウントが2になっているはずなのに動かず
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine.AI; 4using UnityEngine.UI; 5using UnityEngine; 6 7public class Move: MonoBehaviour { 8 9 public GameObject DestroyButton; 10 public GameObject GatheringButton; 11 public GameObject StopProcessingButton; 12 public string Fixationtag = "Fixation"; 13 private NavMeshAgent agent; 14 private RaycastHit hit; 15 private Ray ray; 16 public float count; 17 static Canvas _canvas; 18 19 // Use this for initialization 20 void Start ( ) { 21 22 // Canvasコンポーネントを保持 23 _canvas = GetComponent<Canvas>(); 24 DestroyButton.SetActive(false); 25 GatheringButton.SetActive(false); 26 agent = GetComponent<NavMeshAgent>(); 27 } 28 29 // Update is called once per frame 30 void Update() 31 { 32 if (Input.GetMouseButton(0)) 33 { 34 count += Time.deltaTime; 35 if (count == 2.0f) 36 { 37 Debug.Log("move"); 38 ray = Camera.main.ScreenPointToRay(Input.mousePosition); 39 if (Physics.Raycast(ray, out hit, 100)) 40 { 41 if (hit.collider.gameObject) 42 { 43 agent.SetDestination(hit.point); 44 if (hit.collider.gameObject.CompareTag(Fixationtag)) 45 { 46 agent.SetDestination(hit.point); 47 DestroyButton.SetActive(true); 48 GatheringButton.SetActive(true); 49 Debug.Log("HitTree"); 50 } 51 else 52 { 53 //DestroyButton.SetActive(false); 54 //GatheringButton.SetActive(false); 55 } 56 } 57 } 58 } 59 } 60 else 61 { 62 count = 0; 63 } 64 } 65}
試したこと
デバッグログで確認しつつやったり、2秒後に動くスクリプトを書いてみたのですが2秒になっても動かず
補足情報(FW/ツールのバージョンなど)
Unity 2018.1.1f1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。