I have already found similar questions on stackexchange.com related to accessing variables from another object. But my question seems to have a slightly different context and the answers from those questions are not working.
I have the following (stripped off) scene comprising the standard FPS character:
Scene001
|
|--FPSController
|
|--FirstPersonCharacter
My (stripped off) Assets hierarchy is as follows (folders are enclosed with <> brackets):
<Assets>
|
|--<Scripts>
| |
| |--Actions.cs
|
|--<Standard Assets>
|
|--<Characters>
|
|--<FirstPersonCharacter>
|
|--<Scripts>
|
|--FirstPersonController.cs
Now FirstPersonController.cs is attached to FPSController by default and Actions.cs is attached by me to FirstPersonCharacter.
Excerpt from FirstPersonController.cs is as follows:
...
namespace UnityStandardAssets.Characters.FirstPerson
{
...
public class FirstPersonController : MonoBehaviour
{
...
private void GetCharacter()
{
GameObject _obj = GameObject.Find("FirstPersonCharacter");// ok here
bool is_acted = _obj.GetComponent<Actions>().is_acted; // error here, please see below
}
...
}
}
Excerpt from Actions.cs is as follows:
public class Actions: MonoBehaviour {
...
public static bool is_acted;
...
}
All I want is to access bool is_acted variable of Actions.cs from FirstPersonController.cs.
Error is as follows:
Assets/Standard Assets/Characters/FirstPersonCharacter/Scripts/
FirstPersonController.cs(63,38):error CS0246: The type or namespace
name `Actions' could not be found. Are you missing an assembly reference?
To me this seems to be a problem of namespace or folder location!!?
Any help is highly appreciated. Thanks in advance.
Updated above
- Changed Action to Actions.
- Corrected typo
().
Sample project:
Action.csis attached as a component toFirstPersonCharacterand functions from thatActionclass are running properly. Also, there is only oneFirstPersonCharacterobject i.e. underFPSControllerobject. Pardon me, I might not have understood you. \$\endgroup\$Action.cstoActions.cs, otherwise it is takingSystem.Actionobject. I have updated my question. Kindly wait! I am going to upload my sample project to make it clearer. \$\endgroup\$