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

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

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

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

Unity

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

Q&A

解決済

1回答

1171閲覧

[Mac] Unity error CS0246の箇所がわからない

tuna_onigiri

総合スコア11

C#

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

Unity

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

0グッド

0クリップ

投稿2022/06/09 05:00

編集2022/06/09 06:23

・作っているもの
以前投稿した際の回答にある,ベストアンサーの方の「穴をマウスポインタに向かって伸ばす件について」の方法を自身のunity上でも行おうとしています.

・躓いているところ
スクリプト27行目13列にerror CS0246が発生し,コピペ,手入力,大文字小文字,
unityバージョンを変えてみてもエラーが解消されません.
localkeywordについても調べてみましたが,解決方法がわかりませんでした.

・スクリプト,環境など
▼script(以前の回答者様のscriptコピペです)

using System; using UnityEngine; using UnityEngine.Rendering; [RequireComponent(typeof(Renderer))] public class Hole : MonoBehaviour { private const int SpokeCount = 32; private const float SmoothingThreshold = 0.001f; private static readonly int CenterProperty = Shader.PropertyToID("_Center"); private static readonly int InverseMaxSpokeLengthProperty = Shader.PropertyToID("_InverseMaxSpokeLength"); private static readonly int SpokeLengthsProperty = Shader.PropertyToID("_SpokeLengths"); private static readonly int SmoothingFactorProperty = Shader.PropertyToID("_SmoothingFactor"); [SerializeField][Min(0.0f)] private float maxSpokeLength = 0.4f; // ローカル空間におけるスポークの最大長さ [SerializeField][Min(0.0f)] private float mouseAngleHalfWidth = 15.0f; // スポークの長さが半減するマウスポインタとスポークの角度差 public Vector2 center; // 穴の中心のローカルXY座標 [Min(0.0f)] public float smoothTime = 1.0f; // スポークが目標長さに伸縮するおよその時間 [Range(0.0f, 0.05f)] public float outlineSmoothness = 0.025f; // 穴の輪郭のなめらかさ public bool showDebugGizmos; // スポークとマウスポインタ位置をシーンビュー上に表示するか private readonly Vector2[] spokeDirections = new Vector2[SpokeCount]; private readonly float[] spokeLengths = new float[SpokeCount]; private readonly float[] spokeTargetLengths = new float[SpokeCount]; private readonly float[] spokeVelocities = new float[SpokeCount]; private LocalKeyword enableSmoothing; private Camera mainCamera; private Material material; private float spokeLengthFactor; private void Start() { this.material = this.GetComponent<Renderer>().material; this.enableSmoothing = new LocalKeyword(this.material.shader, "ENABLE_SMOOTHING"); this.mainCamera = Camera.main; for (var i = 0; i < SpokeCount; i++) { var spokeAngle = (2.0f * Mathf.PI * i) / SpokeCount; this.spokeDirections[i] = new Vector2(Mathf.Cos(spokeAngle), Mathf.Sin(spokeAngle)); } this.spokeLengthFactor = (Mathf.Log(0.5f) * Mathf.Rad2Deg * Mathf.Rad2Deg) / (this.mouseAngleHalfWidth * this.mouseAngleHalfWidth); } private void Update() { // まず、マウスポインタの位置をもとに各スポークの目標長さを決める // スポークの向きがマウスポインタの方角からずれるほど、スポークの // 長さを釣り鐘形に割り引くことでなめらかな外形を作る var mouseRay = this.mainCamera.ScreenPointToRay(Input.mousePosition); if (!new Plane(this.transform.forward, this.transform.position).Raycast(mouseRay, out var enter)) { return; } var mouseWorldPosition = mouseRay.GetPoint(enter); var mousePosition = (Vector2)this.transform.InverseTransformPoint(mouseWorldPosition); var relativeMousePosition = mousePosition - this.center; var mouseLength = Mathf.Min(relativeMousePosition.magnitude, this.maxSpokeLength); if (mouseLength > 0.0f) { var mouseDirection = relativeMousePosition.normalized; for (var i = 0; i < SpokeCount; i++) { var angle = Mathf.Acos(Mathf.Clamp(Vector2.Dot(mouseDirection, this.spokeDirections[i]), -1.0f, 1.0f)); this.spokeTargetLengths[i] = Mathf.Exp(this.spokeLengthFactor * angle * angle) * mouseLength; } } else { Array.Fill(this.spokeTargetLengths, 0.0f); } // 各スポークの長さを目標値に向かってなめらかに伸縮させる for (var i = 0; i < SpokeCount; i++) { this.spokeLengths[i] = Mathf.SmoothDamp( this.spokeLengths[i], this.spokeTargetLengths[i], ref this.spokeVelocities[i], this.smoothTime); if (this.showDebugGizmos) { Debug.DrawLine( this.transform.TransformPoint(this.center), this.transform.TransformPoint((this.spokeDirections[i] * this.spokeLengths[i]) + this.center), Color.green); } } // マウスポインタの位置に十字を表示する if (this.showDebugGizmos) { const float crossRadius = 8.0f; var mouseScreenPosition = this.mainCamera.WorldToScreenPoint(mouseWorldPosition); Debug.DrawLine( this.mainCamera.ScreenToWorldPoint(mouseScreenPosition + (Vector3.left * crossRadius)), this.mainCamera.ScreenToWorldPoint(mouseScreenPosition + (Vector3.right * crossRadius)), Color.yellow); Debug.DrawLine( this.mainCamera.ScreenToWorldPoint(mouseScreenPosition + (Vector3.down * crossRadius)), this.mainCamera.ScreenToWorldPoint(mouseScreenPosition + (Vector3.up * crossRadius)), Color.yellow); } // 穴の中心、スポークの長さ、その他マテリアルに必要なデータをセットする this.material.SetVector(CenterProperty, this.center); this.material.SetFloat(InverseMaxSpokeLengthProperty, 1.0f / this.maxSpokeLength); this.material.SetFloatArray(SpokeLengthsProperty, this.spokeLengths); this.material.SetKeyword(this.enableSmoothing, this.outlineSmoothness > SmoothingThreshold); this.material.SetFloat(SmoothingFactorProperty, 1.0f / this.outlineSmoothness); } private void OnDestroy() { Destroy(this.material); } }

上記scriptの27行目13列の

private LocalKeyWord enableSmoothing;

この部分です.

▼エラー文

Assets/Scripts/Hole.cs(27,13): error CS0246: The type or namespace name 'LocalKeyWord' could not be found (are you missing a using directive or an assembly reference?)

▼環境
Mac os 10.13.6
Unity 2019.4.13

windows10でUnity 2020.3.33で実行した際,始めは同様のエラーが出ていたのですが,Ctrl+Dで該当箇所を複製したり消去したりを繰り返していたら,windowsでは急にエラーがなくなりました…

▼以前の質問URL
リンク内容

わかりにくい点,失礼な点がありましたら申し訳ございません.
Macでも実行したい,windowsでもまたエラーが出たら対処できるようにしたいので,windowsで進める以外のご回答がありましたら,よろしくお願いいたします.

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

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

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

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

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

Zuishin

2022/06/09 05:12

> LocalKeyWord いかにも太郎とかジョンとか名無しさんとかいう名前ですが、このような名前のクラスを作っていないのでは? ベストアンサーは解決することを確かめてからにしましょう。
退会済みユーザー

退会済みユーザー

2022/06/09 05:44

OS が Mac だそうですが、それが一目でわかるようにタイトルに入れておいていただけるとありがたいです。
Zuishin

2022/06/09 06:33

> LocalKeyWord いかにも太郎とかジョンとか名無しさんとかいう名前ですが、このような名前のクラスを作っていないのでは? ベストアンサーは解決することを確かめてからにしましょう。
tuna_onigiri

2022/06/09 06:37

Zuishin様 ご回答くださりありがとうございます. クラスについて勉強不足な点があったため,もう一度勉強し直します.
tuna_onigiri

2022/06/09 06:39

SurferOnWww様 タイトルがわかりにくく申し訳ございませんでした. Mac,Unityということがわかるように,修正いたしました.
guest

回答1

0

自己解決

ご回答くださった方ありがとうございました.

using UnityEngine.Rendering;

の入れ忘れでした.

Zuishin様のクラスのご回答により,気がつくことができました.
初歩的なミスでの質問失礼いたしました.

投稿2022/06/09 07:18

tuna_onigiri

総合スコア11

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

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

Bongo

2022/06/09 10:22

すみませんでした、すでにご調査済みかもしれませんがLocalKeyword(https://docs.unity3d.com/2021.2/Documentation/ScriptReference/Rendering.LocalKeyword.html )は2021.2以降からの機能でして、旧バージョンでは使えないかと思います。2021系列がLTSリリースになったのが今年の春でしたので、言及なしに使ったのは早計だったかもしれません。 「using UnityEngine.Rendering;」の追加でうまくいったのでしたらかまわないのですが、もし旧バージョンで動かしたい場合は書き換え案を検討してみようと思います。おそらく、従来からあるEnableKeyword(https://docs.unity3d.com/ja/current/ScriptReference/Material.EnableKeyword.html )、DisableKeyword(https://docs.unity3d.com/ja/current/ScriptReference/Material.DisableKeyword.html )を使って切り替えれば問題ないだろうとは思うのですが...
tuna_onigiri

2022/06/10 08:15

Bongo様 前回の質問に引き続き,コメントしてくださりありがとうございます. using UnityEngine.Rendering; を追加した際,他のエラーは出たのですが,わからないながらに色々調査し試したところ,エラー無く実行できたので自己解決とさせていただきました. 元はこちらがUnityバージョンを記入していなかったことや知識不足が原因ですので,Bongo様が回答してくださったこと,大変感謝しております. Unityのバージョンを2021.3.4にしたところエラー無く実行できました. ご回答ありがとうございます.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問