I am getting an error when attempting to access a method in one script from another script. I asked the question here and was told to ask the question differently.
Alright, I’m using both JS and C# because I’m transitioning to C#, but as I understand it the solution should be almost exactly the same, so, here I go:
animationManager.cs
using UnityEngine;
using System.Collections;
public class animationManager : MonoBehaviour {
// Make this game object and all its transform children
// survive when loading a new scene.
void Awake () {
DontDestroyOnLoad (transform.gameObject);
}
public void sayHello() {
Debug.Log ("hello");
}
}
I have this script attached to a gameObject named “_globalScripts”, which is active in my game.
shipBehavior.js
var kAnimMan : animationManager;
function Start () {
var kGloMan = GameObject.Find("_globalScripts");
kAnimMan = kGloMan.GetComponent(animationManager);
kAnimMan.sayHello();
}
This script is attached to my player’s ship. The script works otherwise and performs a number of actions.
Now, there may be some debate about the code I use inside of Start(), which is what happened the last time I wrote this question out. However, that is of little consequence because the script fails waaay before it arrives there. It actually fails on the kAnimMan declaration, with this error:
Assets/Scripts/Ship/shipBehavior.js(30,16): BCE0018: The name ‘animationManager’ does not denote a valid type (‘not found’). Did you mean ‘UnityEditor.AnimationClipCurveData’?
What I’m doing seems fairly typical. I am creating a global animationManager class and trying to run that sayHello() method on it. But I’ve tried several things, read several articles, and browsed for answers here without any success.
Your help is appreciated.
Edit: Fixed by this answer