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

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

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

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

Unity

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

Q&A

解決済

1回答

317閲覧

別のスクリプトにある変数を呼び出す方法

junachan411

総合スコア15

C#

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

Unity

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

0グッド

0クリップ

投稿2018/10/05 05:54

前提・実現したいこと

BodySourceViewスクリプト内の変数vを、FirstPersonControllerで呼び出したい。
ここに質問の内容を詳しく書いてください。
コンパイル時に The type or namespace name `MyNamespace' could not be found. Are you missing a using directive or an assembly reference? と表示される。

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

6行目 using MyNamespace.Blah;

The type or namespace name `MyNamespace' could not be found. Are you missing a using directive or an assembly reference?

該当のソースコード

C#

1using System; 2using UnityEngine; 3using UnityStandardAssets.CrossPlatformInput; 4using UnityStandardAssets.Utility; 5using Random = UnityEngine.Random; 6using MyNamespace.Blah; 7public class FirstPersonController : MonoBehaviour 8 { 9 [SerializeField] private bool m_IsWalking; 10 [SerializeField] private float m_WalkSpeed; 11 [SerializeField] private float m_RunSpeed; 12 [SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten; 13 [SerializeField] private float m_JumpSpeed; 14 [SerializeField] private float m_StickToGroundForce; 15 [SerializeField] private float m_GravityMultiplier; 16 [SerializeField] private UnityStandardAssets.Characters.FirstPerson.MouseLook m_MouseLook; 17 [SerializeField] private bool m_UseFovKick; 18 [SerializeField] private FOVKick m_FovKick = new FOVKick(); 19 [SerializeField] private bool m_UseHeadBob; 20 [SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob(); 21 [SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob(); 22 [SerializeField] private float m_StepInterval; 23 [SerializeField] private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from. 24 [SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground. 25 [SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground. 26 27 private Camera m_Camera; 28 private bool m_Jump; 29 private float m_YRotation; 30 private Vector2 m_Input; 31 private Vector3 m_MoveDir = Vector3.zero; 32 private CharacterController m_CharacterController; 33 private CollisionFlags m_CollisionFlags; 34 private bool m_PreviouslyGrounded; 35 private Vector3 m_OriginalCameraPosition; 36 private float m_StepCycle; 37 private float m_NextStep; 38 private bool m_Jumping; 39 private AudioSource m_AudioSource; 40 41 42 // Use this for initialization 43 private void Start() 44 { 45 m_CharacterController = GetComponent<CharacterController>(); 46 m_Camera = Camera.main; 47 m_OriginalCameraPosition = m_Camera.transform.localPosition; 48 m_FovKick.Setup(m_Camera); 49 m_HeadBob.Setup(m_Camera, m_StepInterval); 50 m_StepCycle = 0f; 51 m_NextStep = m_StepCycle/2f; 52 m_Jumping = false; 53 m_AudioSource = GetComponent<AudioSource>(); 54 m_MouseLook.Init(transform , m_Camera.transform); 55 56 } 57 58 59 // Update is called once per frame 60 private void Update() 61 { 62 RotateView(); 63 // the jump state needs to read here to make sure it is not missed 64 if (!m_Jump) 65 { 66 m_Jump = CrossPlatformInputManager.GetButtonDown("Jump"); 67 } 68 69 if (!m_PreviouslyGrounded && m_CharacterController.isGrounded) 70 { 71 StartCoroutine(m_JumpBob.DoBobCycle()); 72 PlayLandingSound(); 73 m_MoveDir.y = 0f; 74 m_Jumping = false; 75 } 76 if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded) 77 { 78 m_MoveDir.y = 0f; 79 } 80 81 m_PreviouslyGrounded = m_CharacterController.isGrounded; 82 } 83 ... 84 85 86

###該当のソースコード
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Kinect = Windows.Kinect;
//using MyNamespace.Blash;

namespace MyNamespace.Blash{
public class BodySourceView : MonoBehaviour
{
public Material BoneMaterial;
public GameObject BodySourceManager;

private Dictionary<ulong, GameObject> _Bodies = new Dictionary<ulong, GameObject>(); private BodySourceManager _BodyManager; Kinect.CoordinateMapper _CoordinateMapper; public Camera Camera; Camera _Camera; int SensorWidth = 1920; int SensorHeight = 1080; float matakan_before=0; float matakan_heikatu=0; int count = 0; float[] matakan = new float[7]; int[] omomi = { -2, 3, 6, 7, 6, 3, -2 }; float sokutei_omomi_wa = 0; public float v = 0;

    ...

試したこと

https://stackoverrun.com/ja/q/9273631
を参考に直しましたがエラーが消えません。
BodySourceViewスクリプトの変数vはpublicになっています。

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

Unity 5.4.1f1

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

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

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

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

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

guest

回答1

0

ベストアンサー

恐らくBodySourceView.csにエラーがあってコンパイルが通らない
→その中に書かれたnamespace定義もコンパイルされていないので「MyNamespace.Blash」は存在していない扱いになる
→FirstPersonController.csで「MyNamespaceが見付からない」と怒られる
となっているのではないかと推測します。

FirstPersonControllerを弄る前に、BodySourceViewが正常にコンパイルされているか確認してください。

投稿2018/10/05 06:58

sakura_hana

総合スコア11427

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

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

junachan411

2018/10/10 10:00

回答ありがとうございます。返信おそくなってすいません。いろいろ試していました。 Monodevelopでコードを書いているのですが、BodySourceViewをBuildすると正常にコンパイルされます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問