Question by
alibakhtiar · Nov 03, 2015 at 07:12 AM ·
scripting problemimportgetcomponentoop
Javascript GetComponent not work!
Hi,
I have a tow scripts:
stage.js
net.js
i need include net.js on stage.js, I found this code :
stage.js :
function Start ()
{
var net : net;
net = GetComponent("net");
net.hello();
}
net.js :
public function hello() : int
{
Debug.Log("Hello World");
return 1;
}
but in not work , Error :
NullReferenceException: Object reference not set to an instance of an object
stage.Start ()
I wrote in C#, did not matter, not work!
C# Error!
using UnityEngine;
using System.Collections;
public class Stage : MonoBehaviour
{
private Net net;
// Initialization
void Start () {
net = GetComponent<Net> ();
net.hello();
}
// Update
void Update () {
}
}
using UnityEngine;
using System.Collections;
public class Net : MonoBehaviour {
void hello(){
Debug.Log("Hello");
}
}
Why? help me please. thank you.
Comment
Your answer
Follow this Question
Related Questions
Changing script variable from another script doesn't change it in the original script? 0 Answers
Accessing the sibling of an object 3 Answers
Can't use blur 0 Answers
Getting Value from Function in another Script without knowing Script type 0 Answers
GetComponent returning null inside script, but working well outside 0 Answers