So, I’m doing the Junior Programmer thing on Unity Learn and building a very primitive little game on Unity version 2018.4.33f1 as part of it. It’s a sideways thing where player has to dodge flying balls. It runs exactly as intended but now I get the following console message:
InvalidOperationException: EnsureRunningOnMainThread can only be called from the main thread
UnityEngine.Object.EnsureRunningOnMainThread () (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:153)
I think it has something to do with the particle system because before adding those there was no error message. Any advice?
Here the PlayerController code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float verticalInput;
public float speed = 10.0f;
public ParticleSystem EnergyExplosion;
public ParticleSystem DustExplosion;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
verticalInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.up * verticalInput * Time.deltaTime * speed);
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.layer == 12)
{
Debug.Log("GAME OVER!");
DustExplosion.Play();
Destroy(gameObject);
}
else if (other.gameObject.layer == 11)
{
EnergyExplosion.Play();
Destroy(other.gameObject);
}
}
}