Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class WhenTouchedChangeScene : MonoBehaviour
- {
- public string scene;
- public Transform playerObject;
- public float distance = 2;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- //Debug.LogError("Hello");
- }
- void OnMouseDown()
- {
- var dist = Math.Abs(Vector3.Distance(this.transform.position, playerObject.position));
- Debug.Log("Distance is " + dist);
- if (dist < distance){
- var text = GameObject.Find("GlobalText").GetComponent<Text>();
- text.text = "Loading scene " + scene + "....";
- SceneManager.LoadScene(scene);
- text.text = "Loaded.";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement