美文网首页unity
unity仿真实例

unity仿真实例

作者: Zi_Fi | 来源:发表于2021-02-18 13:35 被阅读0次

3d模式UI界面


image.png

答:


image.png

UI?TestMeshPro?面向摄像机


image.png

答:
方案一:每个小Canvas


image.png
方案二:sprite +button +TextMeshPro
image.png
using UnityEngine;
using System.Collections;
using UnityEngine.Events;

/// <summary>
/// 主要是按钮:
///     a. 默认的点击效果
///     b. 切换点击的图片
/// </summary>
public class ButtonSprite : MonoBehaviour
{

    public enum BTN_TYPE
    {
        DEFAULT,
        NORMAL,
    };

    public string name = "ButtonSprite";
    public BTN_TYPE btnType = BTN_TYPE.DEFAULT;

    private Sprite defauleSprite;
    public Sprite clickedSprite;

    private SpriteRenderer render;

    public UnityEvent OnClick;

    void Start()
    {
        render = GetComponent<SpriteRenderer>();
        defauleSprite = render.sprite;
    }

    void OnMouseDown()
    {
        if (btnType == BTN_TYPE.DEFAULT)
        {
            render.color = Color.gray;
        }
        else if (btnType == BTN_TYPE.NORMAL)
        {
            render.sprite = clickedSprite;
        }
    }

    void OnMouseUp()
    {
        if (btnType == BTN_TYPE.DEFAULT)
        {
            render.color = Color.white;
        }
        else if (btnType == BTN_TYPE.NORMAL)
        {
            render.sprite = defauleSprite;
        }
        Debug.Log("btn clicked!!!");

        if(OnClick!=null)
        {
            OnClick.Invoke();
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FaceToCamera : MonoBehaviour
{

    void Update()
    {
        transform.rotation = Camera.main.transform.rotation;
    }
}

鼠标控制模型旋转


image.png

答:


using UnityEngine;

public class ModelSwitch : MonoBehaviour
{
    private float lastPosX;
    private float lastPosY;
    public Transform CameraX;
    public Transform CameraY;
    private float RotaSpeed;
    public float Speed = 100;
    private float range = 2;

    void Update()
    {
        RotaSpeed = -Speed * Time.deltaTime;

        if (Input.GetMouseButton(1))
        {
            if (Input.mousePosition.x > lastPosX + range)
            {
                CameraX.Rotate(Vector3.up, RotaSpeed,Space.World);
                lastPosX = Input.mousePosition.x;

            }
            else if (Input.mousePosition.x < lastPosX - range)
            {
                CameraX.Rotate(Vector3.up, -RotaSpeed, Space.World);
                lastPosX = Input.mousePosition.x;
            }

            if (Input.mousePosition.y > lastPosY + range)
            {
                CameraY.Rotate(Vector3.right, -RotaSpeed, Space.World);
                lastPosY = Input.mousePosition.y;

            }
            else if (Input.mousePosition.y < lastPosY - range)
            {
                CameraY.Rotate(Vector3.right, RotaSpeed, Space.World);
                lastPosY = Input.mousePosition.y;
            }
        }
    }
}

3D按钮跳到新位置,按钮朝向相机


image.png

点击触发动画


image.png

外发光特效


image.png
image.png

相关文章

网友评论

    本文标题:unity仿真实例

    本文链接:https://www.haomeiwen.com/subject/zqngxltx.html