I found similar posts here and on StackExchange, but they were different from my problem and provided no solution. I need to know how to reference another script from inside this Unity StandardAssets.Cameras namespace. Normally, I can just create a private variable of the same type as the script I want to reference, then fill it using GetComponent. But for some reason when I try to use this same method with one of Unity’s camera scripts, I get the error message in the title.
Here’s the relevant part of the script. I’m getting an error when trying to access my “RiderDismount” script. (This is all in C#) My RiderDismount script is in the following location: Assets–>GG–>Scripts and the AbstractTargetFollower camera script is in Assets–>StandardAssets–>Cameras–>Scripts. Not sure if that’s relevant.
using System;
using UnityEngine;
using Rewired;
namespace UnityStandardAssets.Cameras
{
public abstract class AbstractTargetFollower : MonoBehaviour
{
public enum UpdateType // The available methods of updating are:
{
FixedUpdate, // Update in FixedUpdate (for tracking rigidbodies).
LateUpdate, // Update in LateUpdate. (for tracking objects that are moved in Update)
ManualUpdate, // user must call to update camera
}
[SerializeField] protected Transform m_Target; // The target object to follow
[SerializeField] private bool m_AutoTargetPlayer = true; // Whether the rig should automatically target the player.
[SerializeField] private UpdateType m_UpdateType; // stores the selected update type
protected Rigidbody targetRigidbody;
public int playerId = 0; // The Rewired player ID that this camera will be tied to
public Player player; // The Rewired Player
public float xInputAxis;
public float yInputAxis;
private RiderDismount riderDismount; // ERROR HERE
protected virtual void Start()
{
// if auto targeting is used, find the object tagged "Player"
// any class inheriting from this should call base.Start() to perform this action!
if (m_AutoTargetPlayer)
{
FindAndTargetPlayer();
}
if (m_Target == null) return;
targetRigidbody = m_Target.GetComponent<Rigidbody>();
riderDismount = transform.root.gameObject.GetComponent<RiderDismount>(); // AND ERROR HERE
// Get the Rewired Player object for this player.
player = ReInput.players.GetPlayer(playerId);
}