Hello^, I making a multiplayer in my game by NetworkManager and Console write about this problem’s:
NullReferenceException: Object reference not set to an instance of an object
FloatingPlayer2DController.Spawn () (at Assets/FloatingPlayer2DController.cs:131)
NullReferenceException: Object reference not set to an instance of an object
spavni.Generate () (at Assets/spavni.cs:14)
Code from FloatingPlayer2DController (128-133 lines ) :
if (energy > 71) //128 ;
{ //129;
RaycastHit _hit; //130;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //131 ;
if (Physics.Raycast(ray, out _hit)) //132;
Instantiate(Prefabyy, new Vector3(_hit.point.x, _hit.point.y, _hit.point.z), transform.rotation); /133
And , code , from spavni script (all script’s lines) :
using UnityEngine; //1
public class spavni : MonoBehaviour
{
public GameObject eat;
public float Speed;
void Start ()
{
InvokeRepeating("Generate", 0, Speed);
}
void Generate()
{
int x = Random.Range(0, Camera.main.pixelWidth); //14
int y = Random.Range(0, Camera.main.pixelHeight);
Vector3 Target = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 0));
Target.z = 0;
Instantiate(eat, Target, Quaternion.identity);
}
}
Thank you, it is realy important for game release ^