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

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

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

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Q&A

解決済

1回答

3472閲覧

unityでerror CS0234が解決できません。

rn_unityEngine

総合スコア1

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

0グッド

0クリップ

投稿2023/07/28 08:47

実現したいことここに質問の内容を詳しく書いてください。

(例)
unityでマリオのような2dアクションを作っているのですが下記のエラーがどうしても解決できません。

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

Assets\script\Player.cs(3,26): error CS0234: The type or namespace name 'Eventing' does not exist in the namespace 'System.Diagnostics' (are you missing an assembly reference?)

該当のソースコード

c#

1using System.Collections; 2using System.Collections.Generic; 3using System.Diagnostics.Eventing.Reader; 4using System.Security.Cryptography; 5using System.Text.RegularExpressions; 6using UnityEngine; 7 8public class Player : MonoBehaviour 9{ 10  //インスペクターで設定する 11 public float speed;//速度 12 public float gravity;//重力 13 public float jumpHight;//ジャンプ高度  14 public float jumpSpeed;//ジャンプ速度 15 public float jumpLimitTime; 16 public float stepOnRate; 17 public GroundCheck ground;//設置判定 18 public GroundCheck head; // 頭衝突判定 19 public AnimationCurve dashCurve; 20 public AnimationCurve jumpCurve; 21 22 //プライべーと変数 23 private Rigidbody2D rb = null; 24 private Animator anim = null; 25 private CapsuleCollider2D capcol = null; 26 private bool isGround = false; 27 private bool isJump = false; 28 private bool isDown = false; 29 private bool isHead = false; 30 private bool isOtherJump = false; 31 private float jumpPos = 0.0f; 32 private float jumpTime = 0.0f; 33 private float ohterJumpHeight = 0.0f; 34 private float dashTime = 0.0f; 35 private float beforeKey = 0.0f; 36 private string enemyTag = "Enemy"; 37 38 39 // Start is called before the first frame update 40 void Start() 41 { 42 //コンポーネントのインスタンスを取得する 43 anim = GetComponent<Animator>(); 44 rb = GetComponent<Rigidbody2D>(); 45 capcol = GetComponent<CapsuleCollider2D>; 46 } 47 48 // Update is called once per frame 49 void FixedUpdate() 50 { 51 if (!isDown) 52 { 53 54 //設置判定を見る 55 isGround = ground.IsGround(); 56 isHead = head.IsGround(); 57 58 //キー入力を確認 59 float horizontalKey = Input.GetAxis("Horizontal"); 60 float verticalKey = Input.GetAxis("Vertical"); 61 62 float xSpeed = 0.0f; 63 float ySpeed = -gravity; 64 65 if (isGround) 66 { 67 if (verticalKey > 0) 68 { 69 ySpeed = jumpSpeed; 70 jumpPos = transform.position.y;// ジャンプ高度 71 isJump = true; 72 jumpTime = 0.0f; 73 UnityEngine.Debug.Log("設置判定、キー入力あり"); 74 } 75 else 76 { 77 isJump = false; 78 } 79 } 80 else if (isJump) 81 { 82 //上矢印キーが押されているか 83 bool pushUpKey = verticalKey > 0; 84 //現在の高さはジャンプ可能な高さか 85 bool canHeight = jumpPos + jumpHight > transform.position.y; 86 //ジャンプ時間が長すぎないか 87 bool canTime = jumpLimitTime > jumpTime; 88 89 if (pushUpKey && canHeight && canTime && !isHead) 90 { 91 ySpeed = jumpSpeed; 92 jumpTime += Time.deltaTime; 93 } 94 else 95 { 96 isJump = false; 97 jumpTime = 0.0f; 98 } 99 } 100 101 102 if (horizontalKey > 0) 103 { 104 transform.localScale = new Vector3(1, 1, 1); 105 anim.SetBool("run", true); 106 dashTime += Time.deltaTime; 107 xSpeed = speed; 108 } 109 else if (horizontalKey < 0) 110 { 111 transform.localScale = new Vector3(-1, 1, 1); 112 anim.SetBool("run", true); 113 dashTime += Time.deltaTime; 114 xSpeed = -speed; 115 } 116 else 117 { 118 anim.SetBool("run", false); 119 dashTime = 0.0f; 120 xSpeed = 0.0f; 121 } 122 123 //前回の入力からダッシュの反転を判断して速度を変える。 124 if (horizontalKey > 0 && beforeKey < 0) 125 { 126 dashTime = 0.0f; 127 } 128 else if (horizontalKey < 0 && beforeKey > 0) 129 { 130 dashTime = 0.0f; 131 } 132 beforeKey = horizontalKey; 133 134 //踏みつけジャンプ 135 //現在の高さはジャンプ可能な高さか 136 bool canHeight = jumpPos + otherjumpHight > transform.position.y; 137 //ジャンプ時間が長すぎないか 138 bool canTime = jumpLimitTime > jumpTime; 139 140 if (canHeight && canTime && !isHead) 141 { 142 ySpeed = jumpSpeed; 143 jumpTime += Time.deltaTime; 144 } 145 else 146 { 147 otherjumpHight = false; 148 jumpTime = 0.0f; 149 } 150 151 //アニメーションカーブを速度に適用 152 xSpeed *= dashCurve.Evaluate(dashTime); 153 154 rb.velocity = new Vector2(xSpeed, ySpeed); 155 156 } 157 else 158 { 159 rb.velocity = new Vector2(0, -gravity); 160 } 161 162 } 163 164 private void OnCollisionEnter2D(Collision2D collision) 165 { 166 if (collision.collider.tag == enemyTag) 167 { 168 //踏みつけ判定になる高さ 169 float stepOnHeight = (capcaol.size.y * (stepOnRate / 100f)); 170 171 //踏みつけ判定座標 172 173 float judgePos = transform.position.y - (CaptureCollection.size.y / 2f) + stepOnHeight; 174 175 foreach (ContactPoint2D p in collision.contacts) 176 { 177 if (p.position.y < judgePos) 178 { 179 ObjecCollision o = collision.gameObject.GetComponent<ObjectCollision>(); 180 if (o! = null) 181 { 182 isOtherJumpHeight = o.boundHeight; 183 o.playerStepOn = true; 184 jumpPod = transform.position.y; 185 isOtherJump = true; 186 isJump = false; 187 jumpTime = 0.0f; 188 } 189 else 190 { 191 UnityEngine.Debug.Log("Oobjectcollisonがついてねぇぞ!!!"); 192 } 193 } 194 else 195 { 196 //ダウンする 197 UnityEngine.Debug.Log("敵接触判定あり"); 198 anim.Play("Player_down_animation"); 199 isDown = true; 200 break; 201 } 202 203 } 204 } 205 } 206}

unityのバージョン変更やpcやvsの再起動なども試しましたが、治りませんでした。。

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

ここにより詳細な情報を記載してください。

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

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

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

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

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

fiveHundred

2023/07/28 08:57

System.Diagnostics.Eventingというものは存在しないというエラーです。 System.Diagnostics.Eventingで何をしたいのか、具体的に書かれると、解決策を提示できるかもしれません。
rn_unityEngine

2023/07/28 09:21

System.Diagnost.eventingがなんなのか理解しきれていないのですが、エラーはマリオのように敵を踏みつけるとジャンプをするような挙動を実装しようとしていたときに発生しました。
fiveHundred

2023/07/28 11:04

そんなものにSystem.Diagnostics.Eventingの必要があるとは思えません。 何らかの誤操作や自動挿入によって気づかずに追加された可能性があるので、意図していないのであれば削除してください。
fiveHundred

2023/07/28 11:55

あと「System.Security.Cryptography」とか「System.Text.RegularExpressions」とかもおそらく不要です。
rn_unityEngine

2023/07/28 15:33

System.Diagnostics.Eventingを削除した場合、 Assets\script\Player.cs(31,19): warning CS0414: The field 'Player.ohterJumpHeight' is assigned but its value is never usedやAssets\script\Player.cs(28,18): warning CS0414: The field 'Player.isOtherJump' is assigned but its value is never used等のエラーが出てしまいます。
guest

回答1

0

ベストアンサー

System.Diagnostics.Eventing.Reader 名前空間

System.Diagnostics.Eventing.Reader 名前空間を使用すると、イベント ログの読み取りおよび管理を行うアプリケーションを開発できます。

とあります。
行おうとしていることに必要だとは思えません。
何故using System.Diagnostics.Eventing.Reader;と書かれたのでしょうか?

投稿2023/07/28 10:23

YAmaGNZ

総合スコア10555

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

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

rn_unityEngine

2023/07/28 15:35

ystem.Diagnostics.Eventing.Readerは自動挿入されました。削除したら、Assets\script\Player.cs(30,19): warning CS0414: The field 'Player.ohterJumpHeight' is assigned but its value is never used等のエラーや警告が出てしまいました。
YAmaGNZ

2023/07/28 22:12

The field 'Player.ohterJumpHeight' is assigned but its value is never used これは定義されているけど使われていないという警告です。 エラーメッセージを読みましょう
rn_unityEngine

2023/08/04 12:03

返答おそくなってしまいすみません。エラーメッセージを読みいろいろしたら動くようになりました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.31%

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

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

質問する

関連した質問