photonView is NULL ?
Options
Hello , today i've ran into a problem.
I have a script which handles targeting for spell casting
But for some reason im getting this error
Even tried to use RequireComponent attribute , but still the same error , any thoughts
Thanks in advance.
I have a script which handles targeting for spell casting
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class TargetingHandler : MonoBehaviourPun
{
public bool CanRaycast;
public string returned;
public Vector3 point;
public Summoner summoner;
public Minion minion;
public void Start()
{
CanRaycast = false;
}
public void Update()
{
if (photonView.IsMine)
{
if (CanRaycast == true && Input.GetMouseButtonDown(0))
{
Debug.Log("CanRayCast is true & LMB pressed");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log("Raycasting..");
if (hit.transform.tag == returned)
{
switch (hit.transform.tag)
{
case "Terrain":
Debug.Log("We got terrain");
this.point = hit.point;
CanRaycast = false;
returned = null;
break;
case "Summoner":
Debug.Log("We got summoner");
this.summoner = hit.transform.gameObject.GetComponent();
CanRaycast = false;
returned = null;
break;
case "Minion":
this.minion = hit.transform.gameObject.GetComponent();
Debug.Log("WE got minion" + hit.transform.gameObject.GetComponent());
CanRaycast = false;
returned = null;
break;
}
}
else
{
Debug.Log("Target is not valid");
CanRaycast = false;
return;
}
}
else
{
return;
}
}
}
}
public void WhatWeNeed(string type)
{
switch (type)
{
case "Terrain":
returned = "Terrain";
CanRaycast = true;
break;
case "Summoner":
returned = "Summoner";
CanRaycast = true;
break;
case "Minion":
returned = "Minion";
CanRaycast = true;
break;
}
}
}
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class TargetingHandler : MonoBehaviourPun
{
public bool CanRaycast;
public string returned;
public Vector3 point;
public Summoner summoner;
public Minion minion;
public void Start()
{
CanRaycast = false;
}
public void Update()
{
if (photonView.IsMine)
{
if (CanRaycast == true && Input.GetMouseButtonDown(0))
{
Debug.Log("CanRayCast is true & LMB pressed");
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log("Raycasting..");
if (hit.transform.tag == returned)
{
switch (hit.transform.tag)
{
case "Terrain":
Debug.Log("We got terrain");
this.point = hit.point;
CanRaycast = false;
returned = null;
break;
case "Summoner":
Debug.Log("We got summoner");
this.summoner = hit.transform.gameObject.GetComponent();
CanRaycast = false;
returned = null;
break;
case "Minion":
this.minion = hit.transform.gameObject.GetComponent();
Debug.Log("WE got minion" + hit.transform.gameObject.GetComponent());
CanRaycast = false;
returned = null;
break;
}
}
else
{
Debug.Log("Target is not valid");
CanRaycast = false;
return;
}
}
else
{
return;
}
}
}
}
public void WhatWeNeed(string type)
{
switch (type)
{
case "Terrain":
returned = "Terrain";
CanRaycast = true;
break;
case "Summoner":
returned = "Summoner";
CanRaycast = true;
break;
case "Minion":
returned = "Minion";
CanRaycast = true;
break;
}
}
}
But for some reason im getting this error
NullReferenceException: Object reference not set to an instance of an object TargetingHandler.Update () (at Assets/TargetingHandler.cs:24)I have tried to assign a public photonView variable but it was still acting like the photonView on my GameObject is not existing.
Even tried to use RequireComponent attribute , but still the same error , any thoughts
Thanks in advance.
0