Hello everyone. Just to preface, I am very new to unity, C# scripting, and programming in general, so I apologize in advance if my issue seems trivial. Anyways, I am currently trying to build a game with the ObiFluid asset that will allow a user to control the emission speed of the particle emitter with a key press. I am also trying to make it so Unity will send the key press data to an Arduino board via serial communication. Here is the error that keeps popping up:
[19:50:27] NullReferenceException: Object reference not set to an instance of an object
Obi.Emitter.Speed.Update () (at Assets/EmitterSpeed.cs.37)
I cannot seem to figure out what this error means/implies, and thus have no clue as to how I would fix it.
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
namespace Obi
{
public class EmitterSpeed: MonoBehaviour
{
public SerialPort sp = new SerialPort (“/dev/cu.usbmodem14101”, 9600);
ObiEmitter emitter;
void Start ()
{
sp.Open();
sp.ReadTimeout = 16;
emitter = GetComponent();
}
void Update ()
{
if (Input.GetKey(KeyCode.Alpha1))
{
emitter.speed = 0.5f;
sp.Write(“1”);
}
else if (Input.GetKey(KeyCode.Alpha2))
{
emitter.speed = 1f;
sp.Write(“2”);
}
else
{
emitter.speed = 0f;
}
}
}
}
Thanks in advance.