Hi,
I want to reset to the starting position if the player gets a question wrong.
I have used variable startPos and used the transform.position in the function of the wrong answer buttons. Do I have to used the xyz position of the actual first person controller?
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Question1 : MonoBehaviour {
private Rect windowRect = new Rect (500, 100, 400, 200); //Window size
public bool question1;
private int count;
public Text countText;
Vector3 originalPos = Vector3.zero;
bool reset;
void start()
{
count = 0;
SetCountText ();
}
void Update ()
{
if (reset)
{
reset = true;
ResetPosition();
}
}
void ResetPosition ()
{
transform.position = originalPos;
}
void OnGUI()
{
windowRect = GUI.Window (0, windowRect, WindowFunction, "Ebola Quiz Island"); //window on screen
}
void WindowFunction (int windowID)
{
// Draw any Controls inside the window here
GUI.Label (new Rect (30, 25, 200, 50), " What year did Ebola begin?"); // Question
if (GUI.Button (new Rect (20, 100, 100, 30), "1976")) // Correct Answer
{
Destroy (this.gameObject);
count = count + 1;
SetCountText ();
}
if (GUI.Button (new Rect (280, 100, 100, 30), "1986")) //Wrong answer
{
Destroy (this.gameObject);
ResetPosition();
}
if (GUI.Button (new Rect (20, 150, 100, 30), "1996")) // wrong answer
{
Destroy (this.gameObject);
ResetPosition();
}
if (GUI.Button (new Rect (280, 150, 100, 30), "1966")) // wrong answer
{
Destroy (this.gameObject);
ResetPosition();
}
}
void SetCountText()
{
countText.text = "Score: " + count.ToString ();
}
}