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

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

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

参照は、プログラミングにおいて変数や関数といったメモリ空間上での所在を指示するデータのことを指します。その中にはデータ自体は含まれず、他の場所にある情報を間接的に指示するプログラムです。

C#

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

コンパイルエラー

コンパイルのフェーズで生成されるエラーです。よく無効なシンタックスやタイプが含まれているとき発生します。

Unity

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

Q&A

解決済

1回答

1064閲覧

Error CS1061 について。ディレクティブまたはアセンブリ参照について。

Shogaita

総合スコア5

参照

参照は、プログラミングにおいて変数や関数といったメモリ空間上での所在を指示するデータのことを指します。その中にはデータ自体は含まれず、他の場所にある情報を間接的に指示するプログラムです。

C#

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

コンパイルエラー

コンパイルのフェーズで生成されるエラーです。よく無効なシンタックスやタイプが含まれているとき発生します。

Unity

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

0グッド

0クリップ

投稿2019/10/10 09:32

前提・実現したいこと

コンパイルエラーが出ているので、出ない様にしたいです。
また、参考になる様なネットの記述も、あれば教えて欲しいです。

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

Error CS1061: 'Player' に 'SetDirectionalInput' の定義が含まれておらず、型 'Player' の最初の引数を受け付けるアクセス可能な拡張メソッド 'SetDirectionalInput' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足していないことを確認してください。 (CS1061)

該当のソースコード

C#

1/////Script は、”PlayerInput” と ”Player_R01” 、2つあります。/////////// 2using UnityEngine; 3using System.Collections; 4using System.Collections.Generic; 5 6 7[RequireComponent (typeof (Player))] 8public class PlayerInput : MonoBehaviour 9{ 10 11 Player player; 12 13 void Start () { 14 player = GetComponent<Player> (); 15 } 16 17 void Update () { 18 Vector2 directionalInput = new Vector2 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical")); 19 player.SetDirectionalInput(directionalInput); 20 21 if (Input.GetKeyDown (KeyCode.Space)) { 22 player.OnJumpInputDown(); 23 } 24 if (Input.GetKeyUp (KeyCode.Space)) { 25 player.OnJumpInputUp(); 26 } 27 } 28} 29////////////////////////////////////////////////////////////////////////// 30using UnityEngine; 31using System.Collections; 32using System.Collections.Generic; 33 34[RequireComponent(typeof(Controller2D))] 35public class Player_R01 : MonoBehaviour 36{ 37 38 public float maxJumpHeight = 4; 39 public float minJumpHeight = 1; 40 public float timeToJumpApex = .4f; 41 float accelerationTimeAirborne = .2f; 42 float accelerationTimeGrounded = .1f; 43 float moveSpeed = 6; 44 45 public Vector2 wallJumpClimb; 46 public Vector2 wallJumpOff; 47 public Vector2 wallLeap; 48 49 public float wallSlideSpeedMax = 3; 50 public float wallStickTime = .25f; 51 float timeToWallUnstick; 52 53 float gravity; 54 float maxJumpVelocity; 55 float minJumpVelocity; 56 Vector3 velocity; 57 float velocityXSmoothing; 58 59 Controller2D controller; 60 61 Vector2 directionalInput; 62 bool wallSliding; 63 int wallDirX; 64 65 void Start() 66 { 67 controller = GetComponent<Controller2D>(); 68 69 gravity = -(2 * maxJumpHeight) / Mathf.Pow(timeToJumpApex, 2); 70 maxJumpVelocity = Mathf.Abs(gravity) * timeToJumpApex; 71 minJumpVelocity = Mathf.Sqrt(2 * Mathf.Abs(gravity) * minJumpHeight); 72 } 73 74 void Update() 75 { 76 CalculateVelocity(); 77 HandleWallSliding(); 78 79 controller.Move(velocity * Time.deltaTime, directionalInput); 80 81 if (controller.collisions.above || controller.collisions.below) 82 { 83 velocity.y = 0; 84 } 85 } 86 87 public void SetDirectionalInput(Vector2 input) 88 { 89 directionalInput = input; 90 } 91 92 public void OnJumpInputDown() 93 { 94 if (wallSliding) 95 { 96 if (wallDirX == directionalInput.x) 97 { 98 velocity.x = -wallDirX * wallJumpClimb.x; 99 velocity.y = wallJumpClimb.y; 100 } 101 else if (directionalInput.x == 0) 102 { 103 velocity.x = -wallDirX * wallJumpOff.x; 104 velocity.y = wallJumpOff.y; 105 } 106 else 107 { 108 velocity.x = -wallDirX * wallLeap.x; 109 velocity.y = wallLeap.y; 110 } 111 } 112 if (controller.collisions.below) 113 { 114 velocity.y = maxJumpVelocity; 115 } 116 } 117 118 public void OnJumpInputUp() 119 { 120 if (velocity.y > minJumpVelocity) 121 { 122 velocity.y = minJumpVelocity; 123 } 124 } 125 126 127 void HandleWallSliding() 128 { 129 wallDirX = (controller.collisions.left) ? -1 : 1; 130 wallSliding = false; 131 if ((controller.collisions.left || controller.collisions.right) && !controller.collisions.below && velocity.y < 0) 132 { 133 wallSliding = true; 134 135 if (velocity.y < -wallSlideSpeedMax) 136 { 137 velocity.y = -wallSlideSpeedMax; 138 } 139 140 if (timeToWallUnstick > 0) 141 { 142 velocityXSmoothing = 0; 143 velocity.x = 0; 144 145 if (directionalInput.x != wallDirX && directionalInput.x != 0) 146 { 147 timeToWallUnstick -= Time.deltaTime; 148 } 149 else 150 { 151 timeToWallUnstick = wallStickTime; 152 } 153 } 154 else 155 { 156 timeToWallUnstick = wallStickTime; 157 } 158 159 } 160 161 } 162 163 void CalculateVelocity() 164 { 165 float targetVelocityX = directionalInput.x * moveSpeed; 166 velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne); 167 velocity.y += gravity * Time.deltaTime; 168 } 169}

試したこと

”PlayerInput” の ”using UnityEngine;” 等の記述を追加してみたりしました。
注)あまり、意味は分かっていません。

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

*Mac OS 10.13.6
**Visual Studio 8.3.2

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

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

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

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

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

guest

回答1

0

ベストアンサー

PlayerクラスにSetDirectionalInputの定義がないのではないですか?
提示されているのがPlayer_R01クラスなので、そのあたりを勘違いしていませんか?

投稿2019/10/10 09:43

YAmaGNZ

総合スコア10222

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

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

Shogaita

2019/10/10 09:50

ありがとうございます。 やっと、理解できました。 問題解消できました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問