I want to make drag and drop games. The game can run and play but there is some error. Based on 2 coding below there's an error:-
Full coding:-
Vector3 startposition;
getTarget.transform.position = Vector3.Lerp(getTarget.transform.position, startposition, 1.0f);
startposition = getTarget.GetComponent<Drag>().originalPosition;
1) Error coding on line 80
startposition = getTarget.GetComponent<Drag>().originalPosition;
Full coding:-
if ((dropobject.name == namepartial+"Target") && (getTarget.name == namepartial))
{
startTime = Time.time;
journeyLength = Vector3.Distance(getTarget.transform.position, dropobject.transform.position);
correct = true;
correctdone = false;
if (dropobject.name == "ToasterTarget")
{
infoPanel1.SetActive(true);
infoPanel2.SetActive(false);
infoPanel3.SetActive(false);
infoPanel4.SetActive(false);
infoPanel5.SetActive(false);
infoPanel6.SetActive(false);
infoPanel7.SetActive(false);
}
}
if ((dropobject.name == namepartial+"Target") && (getTarget.name == namepartial))
{
playAudioCorrect();
target.GetComponentInChildren<Renderer>().enabled = false;
getTarget.tag = "Untagged";
int tempscore = int.Parse(scoretext.GetComponent<Text>().text) + 50;
scoretext.GetComponent<Text>().text = tempscore.ToString();
int tempscore1 = int.Parse(finalScoreText.GetComponent<Text>().text) + 50;
finalScoreText.GetComponent<Text>().text = tempscore1.ToString();
}
2) Error coding on line 150:-
if ((dropobject.name == namepartial+"Target") && (getTarget.name == namepartial))
Error from console at line 80 and 105:-
NullReferenceException: Object reference not set to an instance of an object Drag.Update () (at Assets/GameApaNi/Scripts/Drag.cs:105)