3d模式UI界面
答:
UI?TestMeshPro?面向摄像机
答:
方案一:每个小Canvas
方案二:sprite +button +TextMeshPro
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;
}
}
鼠标控制模型旋转
答:
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按钮跳到新位置,按钮朝向相机
点击触发动画
外发光特效