Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Using GetComponent Within OnTriggerEnter

$
0
0
I am having a problem with my code and the error NullReferenceException: Object not set to an instance of an object within the script Sensor. Which is below: using UnityEngine; using System.Collections; using System.Collections.Generic; public class Sensor : MonoBehaviour { private Faction factionType; private ListmUnitsInSensor = new List(); public ListUnitsInSensor { get{return mUnitsInSensor;} set{mUnitsInSensor = value;} } void Awake() { factionType = GetComponentInParent(); mUnitsInSensor.Clear(); } void OnTriggerEnter(Collider other) { Faction otherFaction = other.gameObject.GetComponent(); if(otherFaction.GetFaction != factionType.GetFaction) mUnitsInSensor.Add(other.gameObject); } void OnTriggerExit(Collider other) { mUnitsInSensor.Remove(other.gameObject); } } The line which is returning the error is the if statement within OnTriggerEnter. However the faction script is attached to every single object within the scene and the value set within the inspector. using UnityEngine; using System.Collections; public class Faction : MonoBehaviour { public enum mFaction { TERRAN_EMPIRE, SALAKI_EMPIRE } public mFaction UnitFaction; private mFaction mUnitFaction; public mFaction GetFaction { get{return mUnitFaction;} } void Awake() { mUnitFaction = UnitFaction; } } Therefore I do not understand why it is returning this error exactly. Any help would be greatly appreciated!

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>