Aşağıdaki hatayı çözemiyorum yardımcı olursanız sevinirim:
NullReferenceException: Object reference not set to an instance of an object
quiz.Update () (at Assets/scripts/quiz.cs:25)
scriptler:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class timer : MonoBehaviour
{
[SerializeField] float isAnsweringTime = 30f;
[SerializeField] float showingthetruth = 10f;
public bool isAnswering = true;
public bool timeovernotanswered = false;
float timervalue;
public bool load = false;
quiz quizscript;
public float picoftimer = 1f;
void Update()
{
timerupdate();
}
private void Start() {
timervalue = isAnsweringTime;
quizscript = FindObjectOfType<quiz>();
}
public void CancelTimer()
{
timervalue = 0;
}
void timerupdate()
{
timervalue -= Time.deltaTime;
if (isAnswering==true)
{
if (timervalue <= 0)
{
isAnswering = false;
timervalue = showingthetruth;
Debug.Log("cevaplama süresi doldu");
if (quizscript.notAnswered)
{
timeovernotanswered = true;
}
}
else
{
picoftimer = timervalue/isAnsweringTime;
}
}
if (isAnswering==false)
{
if(timervalue <= 0)
{
isAnswering = true;
timervalue = isAnsweringTime;
Debug.Log("bekleme süresi doldu");
load = true;
}
else
{
picoftimer = timervalue/showingthetruth;
}
}
}
}
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class quiz : MonoBehaviour
{
[SerializeField] TextMeshProUGUI Qtext;
[SerializeField] question Question;
[SerializeField] GameObject[] buttons;
[SerializeField] Sprite afterimage;
[SerializeField] Sprite defaultimage;
[SerializeField] Image timerimage;
timer Timer;
public bool notAnswered = true;
bool buttonBool;
void Start()
{
Timer = FindObjectOfType<timer>();
display();
}
private void Update() {
timerimage.fillAmount = Timer.picoftimer;
if (Timer.load)
{
display();
Timer.load = false;
}
if (Timer.timeovernotanswered)
{
showanswer(-1);
Timer.timeovernotanswered = false;
}
}
void display()
{
notAnswered = true;
setdefaultbuttonsprites();
Qtext.text = Question.GetQ();
for(int i = 0;i<buttons.Length;i++)
{
TextMeshProUGUI buttontext = buttons[i].GetComponentInChildren<TextMeshProUGUI>();
buttontext.text = Question.GetAnswer(i);
}
setbuttonstate(true);
}
void setdefaultbuttonsprites()
{
for(int i = 0;i<buttons.Length;i++)
{
Image buttonimage = buttons[i].GetComponent<Image>();
buttonimage.sprite = defaultimage;
}
}
void setbuttonstate(bool buttonBool)
{
for(int i = 0;i<buttons.Length;i++)
{
Button button = buttons[i].GetComponent<Button>();
button.interactable = buttonBool;
}
}
void showanswer(int index)
{
notAnswered = false;
Timer.timeovernotanswered = false;
if (index == Question.GetCorrect())
{
Qtext.text = "Doğru!";
Image before_image = buttons[index].GetComponent<Image>();
before_image.sprite = afterimage;
}
else
{
Qtext.text = "Doğru Cevap:\n"+Question.GetAnswer(Question.GetCorrect());
Image before_image = buttons[Question.GetCorrect()].GetComponent<Image>();
before_image.sprite = afterimage;
}
setbuttonstate(false);
}
public void OnAnswerSelected(int index)
{
notAnswered = false;
Timer.timeovernotanswered = false;
if (index == Question.GetCorrect())
{
Qtext.text = "Doğru!";
Image before_image = buttons[index].GetComponent<Image>();
before_image.sprite = afterimage;
}
else
{
Qtext.text = "Doğru Cevap:\n"+Question.GetAnswer(Question.GetCorrect());
Image before_image = buttons[Question.GetCorrect()].GetComponent<Image>();
before_image.sprite = afterimage;
}
setbuttonstate(false);
Timer.CancelTimer();
}
}