유 니 티,작은 지도 와 방향 내 비게 이 션 만 들 기.
디자인 요 구 는 방향 내 비게 이 션 이 마우스 회전 에 따라 방향 을 바 꾸 는 것 이다.효과 도 는 다음 과 같다.
구체 적 인 실현 방법 은 UI 디자인 과 스 크 립 트 작성 등 두 가지 절차 가 있다.제 디자인 방향 은 이 컨트롤 이 두 층 으로 나 뉘 는데 첫 번 째 층 은 동서 남북 지시 층 이 고 두 번 째 층 은 아이콘 지시 층 입 니 다.여기 서 제 아이콘 은 원형 아이콘 을 사용 하고 방향 은 여기 서 아이콘 의 회전 을 제어 하 는 방식 으로 이 루어 집 니 다.등급 관 계 는 다음 과 같 습 니 다.
먼저 부모 노드 1 을 만 든 다음 에 부모 노드 에서 하위 노드 2,3 을 만 듭 니 다.마지막 으로 위치 조정 해.
두 번 째 스 크 립 트 작성,스 크 립 트 는 다음 과 같 습 니 다:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class shijiao : MonoBehaviour
{
public GameObject Gcanvas;
public GameObject UIzhinanpicture;
public GameObject Terren;
public GameObject SMAP;
//public GameObject bnt=GameObject.Find("Button");
//
public float sensitivityX = 10F;
public float sensitivityY = 10F;
// (Y )
public float minimumY = -60F;
public float maximumY = 60F;
float rotationY = 0F;
static public bool ifcanvas;
void Update()
{
if(Input.GetMouseButton (0)){
// , ( ), ( X)
float rotationX = transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX;
// ( ), ( Y)
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
// . rotationY min, min. max, max. value
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
//
transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
UIzhinanpicture.transform.localEulerAngles = new Vector3(0,0,- rotationX);
}
}
}
2.유 니 티 작은 지도 제작작은 지도 제작 에 관 해 인터넷 에는 각종 게시 물이 쏟 아 져 나 왔 지만 자세히 보 니 대부분 똑 같 았 고 서로 베 끼 는 것 도 소 용이 없 었 다.각종 게시 물 은 대부분 정교 카메라 의 방식 으로 작은 지 도 를 표시 하지만 이 지 도 는 실제 장면 의 내 려 다 보 는 것 이다.우 리 는 영웅 연맹 과 같은 작은 지도 가 필요 하 다.여기 서 나 는 간단 한 방식 으로 작은 지 도 를 실현 한다.쓸데없는 소리 말고 먼저 효과 도 를 올 려 라.
이곳 의 지 도 는 단지 한 장의 그림 일 뿐,이것 은 지도의 유연성 을 증가 시 켰 다.이곳 의 작은 지 도 는 위의 방향 내 비게 이 션 과 유사 하 며,다른 것 은 스 크 립 트 의 작성 방식 이다.
구체 적 인 실현 도 UI 의 디자인 과 코드 의 작성 으로 두 단계 로 나 뉜 다.
STEP 1:지도 UI 의 디자인
등급 관 계 는 그림 과 같다.
부모 노드 1 은 배경 지도 이 고 하위 노드 2 는 파란색 화살표 이 며 파란색 화살 표 는 목표 가 현재 있 는 위 치 를 나타 낸다.이 두 노드 는 단지 그림 컨트롤 일 뿐이다.
두 번 째 단계:스 크 립 트 작성
스 크 립 트 는 다음 과 같 습 니 다:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using UnityEngine.EventSystems;
public class shijiao : MonoBehaviour
{
public GameObject Gcanvas;//
public GameObject UIzhinanpicture;
public GameObject Terren;//
public GameObject SMAP;//
public GameObject SMAPBK;//
GameObject Cm;
//
public float sensitivityX = 10F;
public float sensitivityY = 10F;
// (Y )
public float minimumY = -60F;
public float maximumY = 60F;
//
float Twidth;
float Tlongth;
//
float mapwidth;
float maplongth;
//
static public float widthScale;
static public float longthscal;
//
//
//static public float PwidthScale;
//static public float Plongthscal;
float rotationY = 0F;
static public bool ifcanvas;
private float movespeed = 20;
CharacterController ctrlor;
void Start ()
{
RenderSettings.fog = false;
ifcanvas =true;
Gcanvas.SetActive (ifcanvas);
Cm = GameObject.Find("Mcam");
ctrlor = GetComponent<CharacterController>();
Twidth=Terren.GetComponent<Collider>().bounds.size.x;
Tlongth =Terren.GetComponent<Collider>().bounds.size.z;
mapwidth = SMAPBK.GetComponent<RectTransform>().rect.width;
maplongth = SMAPBK.GetComponent<RectTransform>().rect.height;
widthScale =(mapwidth) /Twidth;
longthscal =(maplongth) /Tlongth;
SMAP.transform.localPosition= new Vector3(Cm.transform.position.x* widthScale- 50, Cm.transform.position.z* longthscal-50,0);
}
void Update()
{
if (Input.GetMouseButton (1)) {
ifcanvas = true;
Gcanvas.SetActive (ifcanvas);
}
else{
if (Input.GetKey(KeyCode.Escape))
{
ifcanvas = false;
Gcanvas.SetActive (ifcanvas);
}
if (!EventSystem.current.IsPointerOverGameObject())
{
//W
if (Input.GetKey (KeyCode.W)) {
Vector3 forward = transform.TransformDirection(Vector3.forward);
ctrlor.Move(forward*movespeed*Time.deltaTime);
}
//S
if (Input.GetKey(KeyCode.S))
{
Vector3 back = transform.TransformDirection(Vector3.back);
ctrlor.Move(back * movespeed * Time.deltaTime);
}
//A
if (Input.GetKey(KeyCode.A))
{
Vector3 left = transform.TransformDirection(Vector3.left);
ctrlor.Move(left* movespeed * Time.deltaTime);
}
//D
if (Input.GetKey(KeyCode.D) && gameObject.transform.position.y > 0)
{
Vector3 right = transform.TransformDirection(Vector3.right);
ctrlor.Move(right * movespeed * Time.deltaTime);
}
//E
if (Input.GetKey (KeyCode.E)) {
Vector3 upward = transform.TransformDirection(Vector3.up);
ctrlor.Move(upward * movespeed * Time.deltaTime);
}
SMAP.transform.localPosition = new Vector3(Cm.transform.position.x * widthScale - 50, Cm.transform.position.z * longthscal - 50, 0);
if (Input.GetMouseButton (0)){
// ( ), ( X)
float rotationX = transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX;
// ( ), ( Y)
rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
// . rotationY min, min. max, max. value
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
//
transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
UIzhinanpicture.transform.localEulerAngles = new Vector3(0,0,- rotationX);
SMAP.transform.localEulerAngles = new Vector3(0, 0, -rotationX);
}
}
}
}
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
photonnetwork.instantiate에서 gamepobject 유형을 생성 한 다음 상태 및 값을 참조하는 방법주로 마지막 기사에서 일어난 일의 수정입니다. 지난번↓ 그럼 주제입니다. (타이틀이 정리되어 없어서 죄송합니다) 우선 전회의 Illegal view ID:0입니다만 photonnetwork.instantiate를 사...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.