Advertisement
salahzar

WhenTouchedChangeScene.cs

Feb 13th, 2021
1,327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7.  
  8. public class WhenTouchedChangeScene : MonoBehaviour
  9. {
  10.     public string scene;
  11.     public Transform playerObject;
  12.    
  13.     public float distance = 2;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.  
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.         //Debug.LogError("Hello");
  24.     }
  25.     void OnMouseDown()
  26.     {
  27.         var dist = Math.Abs(Vector3.Distance(this.transform.position, playerObject.position));
  28.         Debug.Log("Distance is " + dist);
  29.  
  30.         if (dist < distance){
  31.  
  32.             var text = GameObject.Find("GlobalText").GetComponent<Text>();
  33.             text.text = "Loading scene " + scene + "....";
  34.             SceneManager.LoadScene(scene);
  35.             text.text = "Loaded.";
  36.         }
  37.     }
  38.    
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement