欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

Unity制作小地圖和方向?qū)Ш?/h1>
來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

一、unity方向?qū)Ш街谱?/strong>

設(shè)計要求是方向?qū)Ш诫S著鼠標(biāo)旋轉(zhuǎn)轉(zhuǎn)換方向,效果圖如下:

具體的實現(xiàn)方法主要有兩個步驟,分別為UI設(shè)計和腳本編寫。我的設(shè)計思路是這個控件分為兩層,第一層為東西南北指示層,第二層為圖標(biāo)指示層,這里我的圖標(biāo)采用圓形圖標(biāo),方向指示這里采用控制圖標(biāo)旋轉(zhuǎn)的方式實現(xiàn),層級關(guān)系如下:

首先創(chuàng)建父節(jié)點1,然后在父節(jié)點下創(chuàng)建子節(jié)點2,3;最后調(diào)整好位置。

第二步腳本編寫,腳本如下:

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)){
  //按住鼠標(biāo)左鍵才能調(diào)節(jié)角度,根據(jù)鼠標(biāo)移動的快慢(增量), 獲得相機(jī)左右旋轉(zhuǎn)的角度(處理X) 
  float rotationX = transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX; 

  //根據(jù)鼠標(biāo)移動的快慢(增量), 獲得相機(jī)上下旋轉(zhuǎn)的角度(處理Y) 
  rotationY += Input.GetAxis ("Mouse Y") * sensitivityY; 
  //角度限制. rotationY小于min,返回min. 大于max,返回max. 否則返回value 
  rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); 

  //總體設(shè)置一下相機(jī)角度 
  transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
   UIzhinanpicture.transform.localEulerAngles = new Vector3(0,0,- rotationX);
  }
 }
}

二、unity小地圖的制作

關(guān)于小地圖的制作,網(wǎng)上各種帖子鋪天蓋地,然而仔細(xì)看卻發(fā)現(xiàn)大部分都一樣,互相抄襲,很多都是沒用的。各種帖子大都采用是正交相機(jī)的方式顯示小地圖,然而這個地圖是真實場景的俯視,我們需要的往往是像英雄聯(lián)盟那樣的小地圖,這里我采用一種簡單的方式實現(xiàn)小地圖。廢話不說先上效果圖:

這里的地圖只是一張圖片,這增加了地圖的靈活性,這里的小地圖創(chuàng)建跟上面方向?qū)Ш筋愃?,所不同的是腳本的編寫方式。

具體的實現(xiàn)也是分為兩個步驟,分別為UI的設(shè)計和代碼的編寫。

第一步:地圖UI的設(shè)計

層級關(guān)系如圖:

父節(jié)點1為背景地圖,子節(jié)點2為藍(lán)色箭頭,藍(lán)色箭頭表示目標(biāo)目前所在的位置。這兩個節(jié)點僅僅是圖片控件。

第二步:腳本的編寫

腳本如下:

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鍵前進(jìn)
  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)){
  //根據(jù)鼠標(biāo)移動的快慢(增量), 獲得相機(jī)左右旋轉(zhuǎn)的角度(處理X) 
  float rotationX = transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX; 

  //根據(jù)鼠標(biāo)移動的快慢(增量), 獲得相機(jī)上下旋轉(zhuǎn)的角度(處理Y) 
  rotationY += Input.GetAxis ("Mouse Y") * sensitivityY; 
  //角度限制. rotationY小于min,返回min. 大于max,返回max. 否則返回value 
  rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); 

  //總體設(shè)置一下相機(jī)角度 
  transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
   UIzhinanpicture.transform.localEulerAngles = new Vector3(0,0,- rotationX);
   SMAP.transform.localEulerAngles = new Vector3(0, 0, -rotationX);
  }
  }
  }

 }
}


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有