Can't reference an imported script in one of my own scripts or vice versa.
I have two scripts that I want to reference to each other. One is a script that I have made that controls the core of the game, while the other (the imported one) is the firstpersoncontroller script. All I want to do is set the lock cursor boolean to true or false, given if certain variables are certain values in the core script, but I can't seem to reference the scripts to each other. I have been referencing scripts successfully before, but now Unity just can't seem to understand the type of the scripts I'm trying to reference. Is there something I should know?
Edit:
Sure thing! I can only show so much, so I'll try to compress these scripts a bit to show everything important.
Firstpersonscript:
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
namespace UnityStandardAssets.Characters.FirstPerson
{
[RequireComponent(typeof (CharacterController))]
[RequireComponent(typeof (AudioSource))]
public class FirstPersonController : MonoBehaviour
{
[SerializeField] private bool m_IsWalking;
[SerializeField] private float m_WalkSpeed;
[SerializeField] private float m_RunSpeed;
[SerializeField] [Range(0f, 1f)] private float m_RunstepLenghten;
public float exhaustTime = 5;
public bool isExhausted = false;
public bool initiateCooldown = false;
public float cooldownTime = 7;
public float delayTime = 2;
[SerializeField] private float m_JumpSpeed;
[SerializeField] private float m_StickToGroundForce;
[SerializeField] private float m_GravityMultiplier;
[SerializeField] private MouseLook m_MouseLook;
[SerializeField] private bool m_UseFovKick;
[SerializeField] private FOVKick m_FovKick = new FOVKick();
[SerializeField] private bool m_UseHeadBob;
[SerializeField] private CurveControlledBob m_HeadBob = new CurveControlledBob();
[SerializeField] private LerpControlledBob m_JumpBob = new LerpControlledBob();
[SerializeField] private float m_StepInterval;
[SerializeField] private AudioClip[] m_FootstepSounds; // an array of footstep sounds that will be randomly selected from.
[SerializeField] private AudioClip m_JumpSound; // the sound played when character leaves the ground.
[SerializeField] private AudioClip m_LandSound; // the sound played when character touches back on ground.
private Camera m_Camera;
private bool m_Jump;
private float m_YRotation;
private Vector2 m_Input;
private Vector3 m_MoveDir = Vector3.zero;
private CharacterController m_CharacterController;
private CollisionFlags m_CollisionFlags;
private bool m_PreviouslyGrounded;
private Vector3 m_OriginalCameraPosition;
private float m_StepCycle;
private float m_NextStep;
private bool m_Jumping;
private AudioSource m_AudioSource;
Core script:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerActivate : MonoBehaviour
I'm only showing you a little from the core script, because I feel the problem is originating from the first person script, as the core script hasn't given me problems in the past until I needed to reference this new script.
They are both public, and I just noticed these two lines are above the class declaration for the first person controller:
[RequireComponent(typeof (CharacterController))]
[RequireComponent(typeof (AudioSource))]
If I move the class declaration above these two, the whole script breaks. Could this be doing anything?
This is only assigning the 2 components to your object, I think that nothing to do with the error. Can you post your 2 scripts here?
I've converted $$anonymous$$azYamof comment into an answer.
Answer by KazYamof · May 25, 2016 at 04:00 PM
On your core script, you can declare the FirstPersonController field without error? Because could be the namespace of the other script missing on the core. using UnityStandardAssets.Characters.FirstPerson;