//Jimmy Vegas Unity 5 Tutorial //These scripts will complete objectives 2 and 3 //Objective 2 using UnityEngine.UI; public class Q001Objective02 : MonoBehaviour { public float TheDistance; public GameObject TreasureChest; public GameObject ActionDisplay; public GameObject ActionText; public GameObject TheObjective; public int CloseObjective; public GameObject TakeSword; void Update () { TheDistance = PlayerCasting.DistanceFromTarget; if (CloseObjective == 3) { if (TheObjective.transform.localScale.y <= 0.0f) { CloseObjective = 0; TheObjective.SetActive (false); } else { TheObjective.transform.localScale -= new Vector3 (0.0f, 0.01f, 0.0f); } } } void OnMouseOver () { if (TheDistance <= 3) { ActionText.GetComponent ().text = "Open Chest"; ActionText.SetActive (true); ActionDisplay.SetActive (true); } if (Input.GetButtonDown ("Action")) { if (TheDistance <= 3) { this.GetComponent ().enabled = false; TreasureChest.GetComponent ().Play ("Q01ChestOpen"); TakeSword.SetActive (true); CloseObjective = 3; ActionText.SetActive (false); ActionDisplay.SetActive (false); } } } void OnMouseExit () { ActionDisplay.SetActive (false); ActionText.SetActive (false); } } //=================== //Objective 3 using UnityEngine.UI; public class Q001Objective03 : MonoBehaviour { public float TheDistance; public GameObject FakeSword; public GameObject RealSword; public GameObject ActionText; public GameObject ActionDisplay; public GameObject TheObjective; public int CloseObjective; public GameObject ChestBlock; void Update () { TheDistance = PlayerCasting.DistanceFromTarget; if (CloseObjective == 3) { if (TheObjective.transform.localScale.y <= 0.0f) { CloseObjective = 0; TheObjective.SetActive (false); } else { TheObjective.transform.localScale -= new Vector3 (0.0f, 0.01f, 0.0f); } } } void OnMouseOver () { if (TheDistance <= 3) { ActionText.GetComponent ().text = "Take Sword"; ActionText.SetActive (true); ActionDisplay.SetActive (true); } if (Input.GetButtonDown ("Action")) { if (TheDistance <= 3) { this.GetComponent ().enabled = false; FakeSword.SetActive (false); RealSword.SetActive (true); ChestBlock.SetActive (true); CloseObjective = 3; ActionText.SetActive (false); ActionDisplay.SetActive (false); } } } void OnMouseExit () { ActionDisplay.SetActive (false); ActionText.SetActive (false); } }