- Home /
Question by
Arcoss · May 17, 2014 at 01:08 PM ·
c#triggergetcomponentboolean
How Activating a boolean fron another script(C#)
I've tried using this script and I am getting the following error:Object reference not set to an instance of an object
using UnityEngine;
using System.Collections;
public class Seal_Triggerr : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider Other){
GameObject.Find ("Seal Plate").GetComponent<Plate_Command>().start=true;
}
}
Comment
Answer by AlucardJay · May 17, 2014 at 01:23 PM
Object reference not set to an instance of an object must be the most asked question of all time here ....
This tells you everything !
Didn't find the object you are talking about.
What object? It's hard to determine in your one-liner code. Well, its either the gameobject or the component.
Break It Down ....
//GameObject.Find ("Seal Plate").GetComponent<Plate_Command>().start=true;
GameObject plateObject = GameObject.Find ("Seal Plate");
if ( !plateObject )
{
Debug.LogError( "NO Seal Plate WAS FOUND ...." );
}
Plate_Command plateScript = plateObject.GetComponent<Plate_Command>();
if ( !plateScript )
{
Debug.LogError( "NO Plate_Command WAS FOUND ...." );
}
plateScript.start=true;