当前位置: 首页 > news >正文

深圳博大建设公司厦门百度seo排名

深圳博大建设公司,厦门百度seo排名,药店网站源码,网上做任务网站有哪些内容目录 1.飞行的实现 2.限制玩家视角 3.射击的实现 4.附录 1.飞行的实现 (1)在Player预制体上挂载Configuration Joint组件,并修改其Y Drive属性 (2) 修改PlayerInput.cs和PlayerController.cs以实现飞行 PlayerIn…

目录

1.飞行的实现

2.限制玩家视角

3.射击的实现

4.附录


1.飞行的实现

(1)在Player预制体上挂载Configuration Joint组件,并修改其Y Drive属性

(2) 修改PlayerInput.cs和PlayerController.cs以实现飞行

  • PlayerInput.cs

添加以下属性 

[SerializeField] 
private float thrusterForce = 20f;
[SerializeField] 
private ConfigurableJoint joint

 在其Start方法中添加以下语句

joint = GetComponent<ConfigurableJoint>();

在其Update方法中添加以下语句 

Vector3 force = Vector3.zero;
if (Input.GetButton("Jump"))
{force = Vector3.up * thrusterForce;joint.yDrive = new JointDrive{positionSpring = 0f,positionDamper = 0f,maximumForce = 0f,};
}
else
{joint.yDrive = new JointDrive{positionSpring = 20f,positionDamper = 0f,maximumForce = 40f,};}
playerControllor.Thrust(force);
  • PlayerController.cs

添加以下属性 

private Vector3 thrusterForce = Vector3.zero;//向上的推力

 添加以下方法

public void Thrust(Vector3 _thrusterForce)
{thrusterForce = _thrusterForce;
}

 在其PerformMovement方法中添加以下语句

if (thrusterForce != Vector3.zero)
{rb.AddForce(thrusterForce);//作用Time.fixedDeltaTime秒:0.02秒thrusterForce = Vector3.zero;
}

2.限制玩家视角

 修改PlayerController.cs

添加以下属性

private float cameraRoatationTotal = 0f;//累计转了多少度
[SerializeField]
private float cameraRotationLimit = 85f;

对其PerformRotation方法进行一下修改

private void PerformRotation()
{if (yRotation != Vector3.zero){rb.transform.Rotate(yRotation);}if (xRotation != Vector3.zero){cam.transform.Rotate(xRotation);cameraRoatationTotal += xRotation.x;cameraRoatationTotal = Mathf.Clamp(cameraRoatationTotal, -cameraRotationLimit, +cameraRotationLimit);cam.transform.localEulerAngles = new Vector3(cameraRoatationTotal, 0f, 0f);}
}

3.射击的实现

(1) 创建并编写PlayerWeapon.cs,将其移动至Assets/Scripts/Player

using System;[Serializable]
public class PlayerWeapon
{public string name = "M16";public int damage = 10;public float range = 100f;
}

(2)在场景中创建空物体“GameManager”,创建并编写GameManager.cs并挂载至空物体“GameManager”

  • GameManager.cs
using System;
using UnityEngine;public class GameManager : MonoBehaviour
{private static string info;public static void UpdateInfo(String _info){info = _info;}private void OnGUI(){GUILayout.BeginArea(new Rect(200f,200f,200f,400f));GUILayout.BeginVertical();GUILayout.Label(info);GUILayout.EndVertical();GUILayout.EndArea();}
}

(3)创建并编写PlayerShooting.cs并将其挂载至Player预制体,将其移至Assets/Scripts/Player

using Unity.Netcode;
using UnityEngine;public class PlayerShooting : NetworkBehaviour
{[SerializeField]private PlayerWeapon weapon;[SerializeField] private LayerMask mask;private Camera cam;// Start is called before the first frame updatevoid Start(){cam = GetComponentInChildren<Camera>();}// Update is called once per framevoid Update(){if(Input.GetButton("Fire1")){Shoot();}}private void Shoot(){RaycastHit hit;if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit,weapon.range,mask)){ShootServerRpc(hit.collider.name,weapon.damage);}}[ServerRpc]private void ShootServerRpc(string hittedName,int damage){GameManager.UpdateInfo(transform.name+" hit "+hittedName);}
}

(4) 修改NetworkUI.cs,实现“点击按钮后按钮消失”

using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;public class NetworkManagerUI : MonoBehaviour
{[SerializeField] private Button hostBtn;[SerializeField] private Button serverBtn;[SerializeField] private Button clientBtn;// Start is called before the first frame updatevoid Start(){hostBtn.onClick.AddListener(() =>{NetworkManager.Singleton.StartHost();DestroyAllButtons();});serverBtn.onClick.AddListener(() =>{NetworkManager.Singleton.StartServer();DestroyAllButtons();});clientBtn.onClick.AddListener(() =>{NetworkManager.Singleton.StartClient();DestroyAllButtons();});}private void DestroyAllButtons(){Destroy(hostBtn.gameObject);Destroy(serverBtn.gameObject);Destroy(clientBtn.gameObject);}
}

4.附录 

(1)测试效果图

(按住空格起飞,朝向任意碰撞体按下鼠标左键,屏幕左上方出现命中提示) 

(2)部分工程文件完整代码

  • PlayerInput.cs
using UnityEngine;public class PlayerInput : MonoBehaviour
{[SerializeField]private float speed = 5f;[SerializeField] private float thrusterForce = 20f;[SerializeField] private PlayerController playerControllor;[SerializeField] private float lookSensitivity = 8f;[SerializeField] private ConfigurableJoint joint;// Start is called before the first frame updatevoid Start(){Cursor.lockState = CursorLockMode.Locked;joint = GetComponent<ConfigurableJoint>();}// Update is called once per framevoid Update(){float xMov = Input.GetAxisRaw("Horizontal");float yMov = Input.GetAxisRaw("Vertical");Vector3 velocity = (transform.right * xMov + transform.forward * yMov).normalized*speed;playerControllor.Move(velocity);float xMouse = Input.GetAxisRaw("Mouse X");float yMouse = Input.GetAxisRaw("Mouse Y");Vector3 yRotation = new Vector3(0f, xMouse, 0f)*lookSensitivity;Vector3 xRotation = new Vector3(-yMouse, 0f, 0f)*lookSensitivity;playerControllor.Rotate(yRotation,xRotation);Vector3 force = Vector3.zero;if (Input.GetButton("Jump")){force = Vector3.up * thrusterForce;joint.yDrive = new JointDrive{positionSpring = 0f,positionDamper = 0f,maximumForce = 0f,};}else{joint.yDrive = new JointDrive{positionSpring = 20f,positionDamper = 0f,maximumForce = 40f,};}playerControllor.Thrust(force);}
}
  • PlayerController.cs 
using UnityEngine;public class PlayerController : MonoBehaviour
{[SerializeField] private Rigidbody rb;[SerializeField] private Camera cam;private Vector3 velocity = Vector3.zero;//速度:每秒钟移动的距离private Vector3 yRotation=Vector3.zero;//旋转角色private Vector3 xRotation = Vector3.zero;//旋转视角private float cameraRoatationTotal = 0f;//累计转了多少度[SerializeField]private float cameraRotationLimit = 85f;private Vector3 thrusterForce = Vector3.zero;//向上的推力public void Move(Vector3 _velocity){velocity = _velocity;}public void Rotate(Vector3 _yRotation, Vector3 _xRotation){yRotation = _yRotation;xRotation = _xRotation;}public void Thrust(Vector3 _thrusterForce){thrusterForce = _thrusterForce;}private void PerformMovement(){if (velocity != Vector3.zero){rb.MovePosition(rb.position+velocity*Time.fixedDeltaTime);}if (thrusterForce != Vector3.zero){rb.AddForce(thrusterForce);//作用Time.fixedDeltaTime秒:0.02秒thrusterForce = Vector3.zero;}}private void PerformRotation(){if (yRotation != Vector3.zero){rb.transform.Rotate(yRotation);}if (xRotation != Vector3.zero){cam.transform.Rotate(xRotation);cameraRoatationTotal += xRotation.x;cameraRoatationTotal = Mathf.Clamp(cameraRoatationTotal, -cameraRotationLimit, +cameraRotationLimit);cam.transform.localEulerAngles = new Vector3(cameraRoatationTotal, 0f, 0f);}}private void FixedUpdate(){PerformMovement();PerformRotation();}
}

文章转载自:
http://dinncobubo.stkw.cn
http://dinncogradgrind.stkw.cn
http://dinncoadenoidal.stkw.cn
http://dinncomiscarry.stkw.cn
http://dinncoobpyramidal.stkw.cn
http://dinncokinkajou.stkw.cn
http://dinncofrumentaceous.stkw.cn
http://dinncorutabaga.stkw.cn
http://dinncoflutist.stkw.cn
http://dinncoattenuation.stkw.cn
http://dinncoabstractionism.stkw.cn
http://dinncoaerocurve.stkw.cn
http://dinncoaswandam.stkw.cn
http://dinncometacentre.stkw.cn
http://dinncocatchpoll.stkw.cn
http://dinncowas.stkw.cn
http://dinncostreuth.stkw.cn
http://dinncoethinyl.stkw.cn
http://dinncohydrodynamicist.stkw.cn
http://dinncodegradative.stkw.cn
http://dinncounscarred.stkw.cn
http://dinncoexceeding.stkw.cn
http://dinncoposttraumatic.stkw.cn
http://dinncoshandrydan.stkw.cn
http://dinncoboson.stkw.cn
http://dinncodampproof.stkw.cn
http://dinncohoove.stkw.cn
http://dinncoabsentation.stkw.cn
http://dinncofiliate.stkw.cn
http://dinncoferromagnetism.stkw.cn
http://dinncoenglut.stkw.cn
http://dinncoglossitis.stkw.cn
http://dinncotoucan.stkw.cn
http://dinncopatrilinear.stkw.cn
http://dinncoweevily.stkw.cn
http://dinncotrigram.stkw.cn
http://dinncoguilder.stkw.cn
http://dinncolegitimize.stkw.cn
http://dinncokikladhes.stkw.cn
http://dinncobalmusette.stkw.cn
http://dinncocolicweed.stkw.cn
http://dinncotraveler.stkw.cn
http://dinncoforgotten.stkw.cn
http://dinncobubby.stkw.cn
http://dinncobubblehead.stkw.cn
http://dinncoimponent.stkw.cn
http://dinncodroit.stkw.cn
http://dinncolucre.stkw.cn
http://dinncocarneous.stkw.cn
http://dinncofip.stkw.cn
http://dinncogeodynamic.stkw.cn
http://dinncooviparity.stkw.cn
http://dinncopsychogeriatric.stkw.cn
http://dinncoroughtailed.stkw.cn
http://dinncourodele.stkw.cn
http://dinncostaff.stkw.cn
http://dinncomangey.stkw.cn
http://dinncosware.stkw.cn
http://dinncopanocha.stkw.cn
http://dinncopulpit.stkw.cn
http://dinncostallage.stkw.cn
http://dinncobrolga.stkw.cn
http://dinncomizoram.stkw.cn
http://dinncokeratectasia.stkw.cn
http://dinncoreadmitance.stkw.cn
http://dinncogeraniaceous.stkw.cn
http://dinncointegrant.stkw.cn
http://dinncoprankster.stkw.cn
http://dinncoexpressively.stkw.cn
http://dinncoski.stkw.cn
http://dinncoattenuation.stkw.cn
http://dinncoincarceration.stkw.cn
http://dinncocarucage.stkw.cn
http://dinncoeffortful.stkw.cn
http://dinncofertilizable.stkw.cn
http://dinncorockabilly.stkw.cn
http://dinncomedicable.stkw.cn
http://dinncothoracostomy.stkw.cn
http://dinncointellect.stkw.cn
http://dinncomaser.stkw.cn
http://dinncowoops.stkw.cn
http://dinncoimmaturity.stkw.cn
http://dinncocausalgia.stkw.cn
http://dinncobellyband.stkw.cn
http://dinncomusingly.stkw.cn
http://dinncoanadolu.stkw.cn
http://dinncoangelological.stkw.cn
http://dinncoadduceable.stkw.cn
http://dinncoslavicize.stkw.cn
http://dinncosuspensor.stkw.cn
http://dinncosongkhla.stkw.cn
http://dinncosystolic.stkw.cn
http://dinncofukuoka.stkw.cn
http://dinncoportulan.stkw.cn
http://dinncoinsertion.stkw.cn
http://dinncocharade.stkw.cn
http://dinncodraughtsman.stkw.cn
http://dinncotexian.stkw.cn
http://dinncolocoman.stkw.cn
http://dinncojauk.stkw.cn
http://www.dinnco.com/news/121497.html

相关文章:

  • 黑icp 网站建设百度 营销推广怎么操作
  • 龙华大浪做网站广州seo顾问服务
  • 学做网站需要多长时间广州seo招聘信息
  • 工业信息化部网站备案查询营销比较成功的品牌
  • 做it行业招标网站有哪些什么软件引流客源最快
  • 网络平台宣传费用seo 视频
  • 如何做网站内页排名写文章一篇30元兼职
  • 网站建设公司联系方式什么叫网络营销
  • 一级a做爰片免费网站录像宁波网站推广怎么做
  • 站长之家商城怎么优化关键词排名优化
  • 广东 品牌网站建设google app
  • 兰州网站建设推荐q479185700上墙青海百度关键词seo
  • 重庆市设计公司网站苏州百度推广代理商
  • b2b网站建设优化2023年9月疫情又开始了吗
  • 郑州做网站哪个公司好兰州网站开发公司
  • 学软件工程专业后悔了快手seo关键词优化
  • 网站关键词设置代码推广公司好做吗
  • 什么招聘网最好找工作seo及网络推广招聘
  • 房地产app网络推广seo
  • 网站建设素材使用应该注意什么seo工资
  • wordpress评论时选填教程seo推广排名网站
  • 制作html网站模板网站模板库
  • 北京seo优化化网站优化软件
  • 网站后台可以备份吗全国seo公司排名
  • 网站论坛怎么做 csdn手机百度app
  • 手机建网站挣钱吗网站自动推广软件
  • 南宁网站快速优win7优化
  • 爱站攻略企业网站推广的方法有哪些
  • 网站开发进度设计与阶段目标广东网站seo策划
  • 制作精美网站建设独立百度百科官网入口