質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%

Q&A

解決済

1回答

1027閲覧

Unity2Dエラーメッセージ

nashi-mikan

総合スコア1

0グッド

0クリップ

投稿2020/05/26 10:08

前提・実現したいこと

Unityで2Dアクションのゲームをlogic_labさんのunityでアクションゲームを作ろう!を見ながら作っています。
ゲーム内にサウンドを追加(SE)しようとしたら以下のエラーメッセージが発生しました。
エラーの意味、改善方法などを教えてほしいです。

発生している問題・エラーメッセージ

Assets\PlayerCtrl.cs(5,14): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'System' (are you missing an assembly reference?)

該当のソースコード

C# using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Media; using System.Security.Cryptography; using UnityEngine; using Debug = UnityEngine.Debug; public class PlayerCtrl : MonoBehaviour { public float speed = 5; public float jumpForce = 400f; public LayerMask groundLayer; private Rigidbody2D rd2d; private Animator anim; private SpriteRenderer spRenderer; private bool isGround; private bool isSloped; private bool isDead = false; // Start is called before the first frame update void Start() { this.rd2d = GetComponent<Rigidbody2D>(); this.anim = GetComponent<Animator>(); this.spRenderer = GetComponent<SpriteRenderer>(); Sound.LoadSe("daed", "dead"); } // Update is called once per frame void Update() { float x = Input.GetAxisRaw("Horizontal"); anim.SetFloat("Speed", Mathf.Abs(x * speed)); if (x < 0) { spRenderer.flipX = true; } else if ( x > 0 ) { spRenderer.flipX = false; } if (!isDead) { rd2d.AddForce(Vector2.right * x * speed); } if (isSloped) { this.gameObject.transform.Translate(0.05f * x , 0.0f, 0.0f); } if (Input.GetButtonDown("Jump") & isGround) { rd2d.AddForce(Vector2.up * jumpForce); anim.SetBool("isJump", true); } if (isGround) { anim.SetBool("isJump",false); anim.SetBool("isFall", false); } float velX = rd2d.velocity.x; float velY = rd2d.velocity.y; if (velY > 1f) { anim.SetBool("isJump", true); } if (velY < -1f) { anim.SetBool("isFall", true); } if (Mathf.Abs(velX) > 5) { if (velX > 5.0f) { rd2d.velocity = new Vector2(5.0f, velY); } if (velX < -5.0f) { rd2d.velocity = new Vector2(-5.0f, velY); } } } private void FixedUpdate() { isGround = false; float x = Input.GetAxisRaw("Horizontal"); Vector2 groundPos = new Vector2( transform.position.x, transform.position.y ); Vector2 groundArea = new Vector2(0.5f, 0.4f); Vector2 wallArea1 = new Vector2(x * 0.8f , 1.5f); Vector2 wallArea2 = new Vector2(x * 0.3f , 1.0f); Vector2 wallArea3 = new Vector2(x * 1.5f, 0.6f); Vector2 wallArea4 = new Vector2(x * 1.0f, 0.1f); //Debug.DrawLine(groundPos + wallArea3, groundPos + wallArea4, Color.red); //Debug.DrawLine(groundPos + wallArea1, groundPos + wallArea2, Color.red); //Debug.DrawLine(groundPos + groundArea, groundPos - groundArea, Color.red); isGround = Physics2D.OverlapArea( groundPos+groundArea, groundPos-groundArea, groundLayer ); //Debug.Log(isSloped); bool area1 = false; bool area2 = false; area1 = Physics2D.OverlapArea( groundPos + wallArea1, groundPos + wallArea2, groundLayer ); area2 = Physics2D.OverlapArea( groundPos + wallArea3, groundPos + wallArea4, groundLayer ); if (!area1 & area2) { isSloped = true; } else { isSloped = false; } } IEnumerator Dead() { anim.SetBool("isDamage", true); yield return new WaitForSeconds(0.5f); GetComponent<CircleCollider2D>().enabled = false; Sound.PlaySe("dead",0); } void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "Damage") { isDead = true; StartCoroutine("Dead"); } }

試したこと

このプログラムを書き込むまではエラーメッセージは出なかったので下記のようにコメントにしました。
しかしエラーが消えることはありませんでした。
//Sound.LoadSe("daed", "dead");
//Sound.PlaySe("dead",0);

補足情報(FW/ツールのバージョンなど)

Unity2D ver2019.3.14f1

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sakura_hana

2020/05/27 00:43

「using System.Media;」この行をコメントアウトするとどうなりますか?
nashi-mikan

2020/05/27 10:18

エラーメッセージが消えました どうゆうことでしょうか?
sakura_hana

2020/05/28 00:34

エラーメッセージをそのまま読むと「namespace 'System'には'Media'というnamespaceはありません」という意味です。 参考資料を見ていないのですが、もしこれをコメントアウトして正常に動作するなら、誤って入力してしまったのかなと思った次第です。(正常に動作しないなら「System.Mediaが必要なのに無いとエラーが出る」という別の問題になります)
nashi-mikan

2020/05/28 13:20

ありがとうございます。 エラーがなぜ起こったか自分で入力した覚えもないのでわかりませんが なおったので良かったです。
guest

回答1

0

自己解決

using System.Mediaをコメントアウトする。

投稿2020/05/28 13:21

nashi-mikan

総合スコア1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問