void Update() { if(Input.GetMouseButtonUp(0)){ // if is click if(mouseDownCount < 2){ // click to navigate RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, out hit, Mathf.Infinity)){ // move when hit floor if(hit.transform.tag == "Floor"){ agent.SetDestination(hit.point);
// rotate camera up and down cameraRotation -= mouseY; cameraRotation = Mathf.Clamp(cameraRotation, -30f, 30f); cameraTransform.localRotation = Quaternion.Euler(cameraRotation, 0f, 0f);
// rotate player left and right transform.Rotate(Vector3.up * (mouseX));
private Text displayArtTitle; private Text displayArtDescription;
private float dist;
private bool check;
void Start() { // get player transform playerTransform = GameObject.FindWithTag("Player").GetComponent<Transform>();
// get UI text displayArtTitle = GameObject.FindWithTag("ArtTitle").GetComponent<Text>(); displayArtDescription = GameObject.FindWithTag("ArtDescription").GetComponent<Text>();
// set default text displayArtTitle.text = ""; displayArtDescription.text = "";
check = false; }
// Update is called once per frame void Update() { if(playerTransform) { // distance between art and player dist = Vector3.Distance(transform.position, playerTransform.position); if (dist < displayTextDistance) { displayArtTitle.text = title; displayArtDescription.text = description; check = true; } // turn off display if (dist > displayTextDistance && check == true) { Start(); } } } }