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

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

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

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

2055閲覧

接地判定作り中のエラーについて

sabaimo

総合スコア1

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2021/04/10 01:43

参考にしていたサイト
このサイトを参考に接地判定を作ろうとしていたのですがエラーがたくさん出てきてしまいどうすればよいかわからなくなりました

エラーメッセージ

Assets\ground.cs(12,36):

1Assets\ground.cs(12,40): error CS1002: ; expected 2Assets\ground.cs(12,40): error CS1513: } expected 3Assets\ground.cs(14,10): error CS8641: 'else' cannot start a statement. 4Assets\ground.cs(14,10): error CS1003: Syntax error, '(' expected 5Assets\ground.cs(14,10): error CS1525: Invalid expression term 'else 6Assets\ground.cs(14,10): error CS1026: ) expected 7Assets\ground.cs(14,10): error CS1002: ; expected 8Assets\ground.cs(17,30): error CS1002: ; expected 9Assets\ground.cs(17,30): error CS1513: } expected

の10個のエラーです

該当のソースコード

C#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class ground : MonoBehaviour 6{ 7 8 private bool isGround = false; 9 private bool isGroundEnter, isGroundStay, isGroundExit; 10 11 public bool IsGround() 12 {if (isGroundEnter || isGround Stay){ 13 isGround = true; 14 } 15 else if (isGroundExit) 16 { isGround = false; } 17 isGroundEnter = false: 18 isGroundStay = false; 19 isGroundExit = false; 20 retuen isGround; 21 } 22 23 private void OnTriggerEnter(collider collision) 24 { isGroundEnter = true;} 25 26 private void OnTriggerStay(collider collision) 27 { isGroundStay = true; } 28 29 private void OnTriggerExit(collider collision) 30 { isGroundExit = true; } 31 32 // Start is called before the first frame update 33 void Start() 34 { 35 36 } 37 38 // Update is called once per frame 39 void Update() 40 { 41 42 } 43} 44

試したこと

エラーの理由を調べたがわからなかった
一部自分で作った

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

unity 2020
Microsoft Visual studio

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

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

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

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

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

guest

回答1

0

ベストアンサー

エラー原因は、スペルミスや入力誤りによるものです。
基本はエラーログを参照して修正するのですが、確かに一部はエラーログからだけでは分かりづらいです。
そういった場合は、エディタの入力文字に対して、赤いアンダーラインが出てないかなどを見ると、入力誤りに気づくかと思います。

修正例
波かっこ("{}")は改行して入力することが一般的なので、改行も一部変えてます。

C#

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class ground : MonoBehaviour 6{ 7 8 private bool isGround = false; 9 private bool isGroundEnter, isGroundStay, isGroundExit; 10 11 public bool IsGround() 12 { 13 // 修正: "isGround Stay"だったのを"isGroundStay"に変更(不要なスペース削除) 14 if (isGroundEnter || isGroundStay){ 15 isGround = true; 16 } else if (isGroundExit){ 17 isGround = false; 18 } 19 20 isGroundEnter = false; // 修正:行末がセミコロンではなく、コロンになっていた。セミコロンに修正 21 isGroundStay = false; 22 isGroundExit = false; 23 24 // 修正: "retuen"だったのを"return"に変更(スペルミス修正) 25 return isGround; 26 } 27 28 // 修正:"collider"を、"Collider"に変更 29 private void OnTriggerEnter(Collider collision){ 30 isGroundEnter = true; 31 } 32 33 // 修正:"collider"を、"Collider"に変更 34 private void OnTriggerStay(Collider collision) { 35 isGroundStay = true; 36 } 37 38 // 修正:"collider"を、"Collider"に変更 39 private void OnTriggerExit(Collider collision) 40 { 41 isGroundExit = true; 42 } 43 44 // Start is called before the first frame update 45 void Start() 46 { 47 48 } 49 50 // Update is called once per frame 51 void Update() 52 { 53 54 } 55}

投稿2021/04/10 02:46

編集2021/04/10 02:53
tsuki01

総合スコア1751

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問