0
\$\begingroup\$
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Zombie_Spawn : MonoBehaviour
{
    public float timer = 0.0f;
    public bool m_spawn = false;
    public GameObject m_Zombie;
    Vector2 pos;

    void Update()
    {        
        if (m_spawn == true)
        {
            timer += Time.deltaTime;
            if (timer > 2.0f)
            {
                pos = Camera.current.ViewportToWorldPoint(new Vector2(1f, 0.135f)); //this executes fine but will Null out randomly
                Instantiate(m_Zombie, pos, Quaternion.identity);
                timer = 0;
            }                
        }
        else
        {
            timer = 0f;
        }
    }
}
\$\endgroup\$
  • \$\begingroup\$ And the exception (not expectation) says what? \$\endgroup\$ – user253751 Mar 14 '18 at 21:40
0
\$\begingroup\$

It's clearly written in the documentation:

Use this function (Camera.current) only when implementing one of the following events: MonoBehaviour.OnRenderImage, MonoBehaviour.OnPreRender, MonoBehaviour.OnPostRender.

Outside of those three callbacks, you need to use Camera.main

\$\endgroup\$