チュートリアルのサバイバルシューターをやっているのですがScoring points のとこで詰まりました。
敵をたおしてもスコアに反映されません。
動作として理解できないのがScoreManager.score += scoreValue;の部分でなぜGetComponentもせずにScoreManagerがインスタンスのように使えているのでしょうか?(自分は使えていませんが)
using UnityEngine; using UnityEngine.UI; using System.Collections; namespace CompleteProject { public class ScoreManager : MonoBehaviour { public static int score; // The player's score. Text text; // Reference to the Text component. void Awake () { // Set up the reference. text = GetComponent <Text> (); // Reset the score. score = 0; } void Update () { // Set the displayed text to be the word "Score" followed by the score value. text.text = "Score: " + score; } } }
using UnityEngine; public class EnemyHealth : MonoBehaviour { public int startingHealth = 100; public int currentHealth; public float sinkSpeed = 2.5f; public int scoreValue = 10; public AudioClip deathClip; Animator anim; AudioSource enemyAudio; ParticleSystem hitParticles; CapsuleCollider capsuleCollider; bool isDead; bool isSinking; void Awake () { anim = GetComponent <Animator> (); enemyAudio = GetComponent <AudioSource> (); hitParticles = GetComponentInChildren <ParticleSystem> (); capsuleCollider = GetComponent <CapsuleCollider> (); currentHealth = startingHealth; } void Update () { if(isSinking) { transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime); } } public void TakeDamage (int amount, Vector3 hitPoint) { if(isDead) return; enemyAudio.Play (); currentHealth -= amount; hitParticles.transform.position = hitPoint; hitParticles.Play(); if(currentHealth <= 0) { Death (); } } void Death () { isDead = true; capsuleCollider.isTrigger = true; anim.SetTrigger ("Dead"); enemyAudio.clip = deathClip; enemyAudio.Play (); } public void StartSinking () { GetComponent <UnityEngine.AI.NavMeshAgent> ().enabled = false; GetComponent <Rigidbody> ().isKinematic = true; isSinking = true; ScoreManager.score += scoreValue; Destroy (gameObject, 2f); } }
試したこと
Debug.Log(ScoreManager.score);をStartSinking ()に追加してコンソールに値を表示したところ値は10でした
Debug.Log(ScoreManager.score);をプレイヤーが銃を撃った時に実行されるようにしたところ値は0、敵を倒した後だと10
Debug.Log(ScoreManager.score);をScoreManagerのUpdateに追加したところずっと0
エラー文?
コンソールに表示した値をダブルクリックすると表示される
InvalidOperationException: Cannot start process because a file name has not been provided. System.Diagnostics.Process.Start () (at <d465e2b2e5054d2787d6364114c43446>:0) (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start() UnityEditor.DefaultExternalCodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/DefaultExternalCodeEditor.cs:96) Unity.CodeEditor.CodeEditor.OpenFileAtLineColumn (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/CodeEditor.cs:31) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Exception thrown while invoking [OnOpenAssetAttribute] method 'Unity.CodeEditor.CodeEditor:OnOpenAsset (int,int,int)' : InvalidOperationException: Cannot start process because a file name has not been provided. System.Diagnostics.Process.Start () (at <d465e2b2e5054d2787d6364114c43446>:0) (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start() UnityEditor.DefaultExternalCodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/DefaultExternalCodeEditor.cs:96) Unity.CodeEditor.CodeEditor.OnOpenAsset (System.Int32 instanceID, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/CodeEditor.cs:62) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/12 08:21 編集
2019/06/12 08:41
2019/06/12 08:59
2019/06/12 09:03
2019/06/12 09:10
2019/06/12 09:17
2019/06/12 09:52
2019/06/12 10:01
2019/06/12 10:22
2019/06/12 11:38
2019/06/12 12:10