
[ad_1]
I’ve a category that’s an occasion supervisor, which is notifying different scripts of contact occasions. However, the issue is that whereas the primary public static occasion – SendInteraction – works, the second occasion, ShipDrag, doesn’t appear to be sending the place to the subscribed class. Instead, it simply prints a null reference error.
“NullReferenceException: Object reference not set to an occasion of an object
TouchScreenManager.Update () (at ../TouchScreenManager.cs:47)”
I’ve tried making the TouchScreenManager class a Singleton and eradicating references to the occasions as static, and as an alternative creating new situations in every subscribed class in Awake() however that does not work both. How can I repair it?
public class TouchScreenManager : MonoBehaviour
{
#area occasions
public delegate void SendInteraction(RecreationObject merchandise);
public static occasion SendInteraction MoveScene;
public delegate void ShipDrag(Vector2 place);
public static occasion ShipDrag Drag;
#endregion
non-public Vector3 startPos;
non-public Vector2 startPosition;
non-public WaitForFixedUpdate waitForFixedUpdate = new WaitForFixedUpdate();
void Awake()
{
EnhancedTouchHelp.Enable();
TouchSimulation.Enable();
}
void Update()
{
if (Touch.activeFingers.Count == 1)
{
var contact = Touch.energeticTouches[0];
if (contact.part == TouchSection.Began)
{
startPosition = contact.startScreenPosition;
startPos = Camera.primary.ScreenToWorldPoint(contact.screenPosition);
DragAndDrop(contact);
CheckForInteraction(contact);
}
else if (contact.part == TouchSection.Moved)
{
Debug.Log("from the contact display screen supervisor:" + contact.screenPosition);
Drag(contact.screenPosition); // PRINTS FINE HERE
}
}
}
This script is subscribed to this occasion.
public class LineGenerator : MonoBehaviour
{
public RecreationObject linePrefab;
Line energeticLine;
Vector2 capturedScreenPos;
non-public void OnEnable()
{
TouchScreenManager.Drag += DrawLine;
}
non-public void OnDisable()
{
TouchScreenManager.Drag -= FullLine;
}
void DrawLine(Vector2 place)
{
RecreationObject newLine = Instantiate(linePrefab);
energeticLine = newLine.GetComponent<Line>();
capturedScreenPos = place;
Debug.Log("from the road generator: " + place); // NULL REF HERE
}
}
````
[ad_2]