I'm trying to edit the values of a script that I attach to a gameobject however, I get a NullReferenceException. Here's the code where I'm calling the other script and it variables:
if (go.GetComponent() == null)
{
go.AddComponent();
SimpleConsole.print("ATTACHED SCRIPT");
}
poiList.Add(go);
SimpleConsole.print("ADDED POI TO LIST");
attchas test = GameObject.Find(param.getAtIndex(1).iData.ToString()).GetComponent();
SimpleConsole.print("SET TEST");
test.sp.contactOffset = param.getAtIndex(3).fData;
SimpleConsole is the name of an Debug Console asset I'm using to test the various features of my program. SimpleConsole.print just prints to the console. With that said, it reaches "SET TEST" then thats when I get my error.
Heres the other script "attchas":
using UnityEngine;
using System.Collections;
public class attchas : MonoBehaviour {
public AudioSource ao = new AudioSource();
public SphereCollider sp = new SphereCollider();
void Update()
{
Vector3 pos1 = sp.transform.position;
if (!ao.isPlaying & ao != null & sp != null & Vector3.Distance(GameObject.FindGameObjectWithTag("Player").transform.position, pos1) <= sp.contactOffset)
{
ao.Play();
}
else if (ao.isPlaying & ao != null & sp != null & Vector3.Distance(GameObject.FindGameObjectWithTag("Player").transform.position, pos1) > sp.contactOffset)
{
ao.Pause();
}
}
}
If anyone could give me a good idea of where to start investigating I would be grateful.
↧