- Home /
Definition problem
I have a very complex and complicated script.(consist of more scripts actually, but lets focus on this single one)But cut down, I want to activate another public void in another script from this one: The problem is that, when I run PickMeUp I get a NullRefferenceException error. It apears that I havent defined the PrivatePositionUpdate variable.
public GameObject ThisGameobject;
public Private_position_Update PrivatePositionUpdate;
public GameObject[] obstacles ;
void Awake()
{
obstacles = GameObject.FindGameObjectsWithTag("obstacle");
Debug.Log(obstacles);
}
void PickMeUp()
{
foreach (GameObject _obstacle in obstacles) {
PrivatePositionUpdate = _obstacle.GetComponent<Private_position_Update>();
Destroy(ThisGameobject);
PrivatePositionUpdate.RemoveOfGadget();
}
}
}
I need an answer pretty badly on this... I have a deadline next week on this game and this is part of a major core game mechanic.
Answer by Meltdown · Mar 14, 2012 at 08:33 PM
You need to have a script/class called Private_position_Update added to your obstacle gameobject.
Also I suggest checking if _obstacle is not null, and if PrivatePositionUpdate is not null.
Also why you are naming a class 'Private_position_Update' is beyond me.
I'm trying to access another script called Private_Position_Update.cs. $$anonymous$$y question is: How do I do that?
Thank you $$anonymous$$eltdown. It was helpfull, but not the exact thing I was looking for... $$anonymous$$y problem is that my gameobject gets destroyed before it can send the message out to my Private_position_Update script. And moving the Destroy(ThisGameobject); doesnt work
I know that in javascript I'd use var SomethingSomething = GetComponent("ScriptName")... And so on.
Your answer
Follow this Question
Related Questions
C# Getting a certain AnimationState using strings from all objects with specific tag 2 Answers
trying to define the last object I collided with and store it as a variable? 2 Answers
How to make an Array equal the Components of an Instantiated GameObject 1 Answer
Calculating the lowest number 3 Answers
Foreach with GameObject.Find() 1 Answer