场景切换+鼠标放在物体上显示名字

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class showSwitch : MonoBehaviour {
    bool isShowName,isSwitchSence;
	void Start () {
        isShowName = false;
        isSwitchSence = false;
	}
    void OnMouseEnter()
    {
        isShowName = true;
    }
    void OnMouseExit()
    {
        isShowName = false;
    }
    private void OnGUI()
    {
        if(isShowName)
        {
            GUIStyle style1 = new GUIStyle();
            style1.fontSize = 30;
            style1.normal.textColor = Color.red;
            GUI.Label(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 400, 50), this.name, style1);
        }
    }
    void OnCollisionEnter(Collision other)
    {
        if (string.Equals("StartCity", other.gameObject.name))
        {
            isSwitchSence = true;
        }
    }
    void OnCollisionExit(Collision other)
    {
            isSwitchSence = false;
    }
    void OnMouseDown()
    {
        if (isSwitchSence)
        {
           SceneManager.LoadScene("StartCity");
           DontDestroyOnLoad(this);
           DontDestroyOnLoad(GameObject.Find("Camera"));
           transform.position = new Vector3(800,32,700);
        }
    }
    void Update () {	}
}

你可能感兴趣的:(学习笔记)