I am a noob a programer but I can't find how to find a solution to this error:
NullReferenceException: Object reference not set to an instance of an object
CTF.Changing_Color.ChangingFlagColor () (at Assets/Scripts/Changing_Color.cs:29)
CTF.Changing_Color.Start () (at Assets/Scripts/Changing_Color.cs:16)
My Code:
using UnityEngine;
using System.Collections;
namespace CTF {
public class Changing_Color : MonoBehaviour
{
private RaycastHit hit;
public GameObject Red;
public GameObject Blue;
public GameObject Neutral;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
ChangingFlagColor();
}
void ChangingFlagColor()
{
if(hit.transform.CompareTag("Blue"))
{
Red.SetActive(false);
Blue.SetActive(true);
Neutral.SetActive(false);
}
if (hit.transform.CompareTag("Red"))
{
Red.SetActive(true);
Blue.SetActive(false);
Neutral.SetActive(false);
}
}
}
}
↧