切换视角(视角递增and递减)
//ViewChanged脚本需绑定在主相机上
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ViewChanged : MonoBehaviour, IPointerClickHandler
{
public Button SubBtn;//减少视角按钮
public Button AddBtn;//增大视角按钮
public Text ShowTxt;
public GameObject _3DGameParent;
public int no = 1;
void Start()
{
ShowTxt.text = "1";
SubBtn.GetComponent<Button>().onClick.AddListener(delegate
{
this.OnClick1(SubBtn.GetComponent<Button>());
});
AddBtn.GetComponent<Button>().onClick.AddListener(delegate
{
this.OnClick2(AddBtn.GetComponent<Button>());
});
}
void OnClick1(Button btn)
{
if (no > 1)
{
int j;
j = int.Parse(ShowTxt.text) - 1;
ShowTxt.text = j.ToString();
no--;
}
ViewNumChoose(no);
}
void OnClick2(Button btn)
{
if (no < 6)
{
int i;
i = int.Parse(ShowTxt.text) + 1;
ShowTxt.text = i.ToString();
no++;
}
ViewNumChoose(no);
}
#region 根据切换的视角,旋转物体
private void ViewNumChoose(int num)
{
_3DGameParent.transform.position = Vector3.zero;
switch (num)
{
case 1:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 0, 0);
// _3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.right);
break;
case 2:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 90, 0);
// _3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.back);
break;
case 3:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 180, 0);
//_3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.left);
break;
case 4:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 270, 0);
// _3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.forward);
break;
case 5:
_3DGameParent.transform.localRotation = Quaternion.Euler(90, 0, 0);
//_3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.up);
break;
case 6:
_3DGameParent.transform.localRotation = Quaternion.Euler(270, 0, 0);
//_3DGameParent.transform.LookAt(-_3DGameParent.transform.position + Vector3.down);
break;
default:
break;
}
}
#endregion
void Update ()
{
}
public void OnPointerClick(PointerEventData eventData)
{
throw new System.NotImplementedException();
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步