- Home /
An object reference is required when checking for active object
So I'm trying to check to see if an object is active or not and I'm running into the CS0120 error (An object reference is required to access non-static member). My goal is to create a teleporter script that works for multiple entrances and exits. The problem is that many of the entrances are large planes that intersect or are in locations where I don't want them to be active until later.
Here is my script.
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public Transform teleportTo;
void OnCollisionExit(Collision col)
{
if (GameObject.activeSelf = true)
{col.transform.position = teleportTo.position;}
}
}
Thanks in advance.
try changing the uppercase GameObject to gameObject if that's the line causing the error, if not (and for any future posts...) please include the line# with any report of an error.
Answer by DiligentGear · Mar 14, 2014 at 03:25 AM
Change
if (GameObject.activeSelf = true)
to
if (col.gameObject.activeSelf == true)
"GameObject" is a class while col.gameObject is the reference of game object you collide with.
Your answer

Follow this Question
Related Questions
For some reason Object reference not set to instance of an object 2 Answers
Object.operator bool evaluates oddly 1 Answer
How do I fix this problem-it won't let me start my game in Unity because of an override problem 1 Answer
NullReferenceException: Object reference not set to an instance of an object 0 Answers
Animation stops working after SetActiveRecursively() 1 Answer