Unity 5 Accessing other scripts problem
Since I upgraded my unity from 4 to 5 I keep getting errors I never did before. Here's the error I get when I try to access other scripts:
The name 'DoorKey' does not denote a valid type ('not found').
Here's the script I used:
#pragma strict
var key : DoorKey = GetComponent(DoorKey);
var block : GameObject;
function Start () {
}
function Update () {
if(key.door == gameObject) {
if(key.taken) {
block.SetActive(false);
}
}
}
I also tried using different versions such as:
var key : DoorKey = GetComponent("Door Key");
var key : DoorKey = GetComponent.<DoorKey>();
And even tried changing the DoorKey to a GameObject but still..
var key : GameObject = GetComponent(DoorKey);
Why does this happed? Thanks!
Answer by Jason2014 · May 02, 2016 at 02:43 PM
You have to reference to component in function using variable and get component from it.
var key : DoorKey;
var block : GameObject;
function Awake ()
{
key = GetComponent.<DoorKey> ();
}
[rest of code...]
Also make sure that 'key' and 'taken' variables are public.
Answer by gdv · May 06, 2016 at 11:56 AM
Found the problem. The script's name was "Door Key.js". I removed the spaces("DoorKey.js") and everything worked fine! Thanks tho
Your answer
Follow this Question
Related Questions
Moving script wont even move enemy no more? 0 Answers
Coin Bank Issues in [Code C#] 0 Answers
Dragging an object to variable: Problems in the editor! 2 Answers
How can I use the same script for multiple gameobjects? 1 Answer
scripting problems please help 0 Answers