当前位置: 首页 > 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://www.ds6.com.cn/news/8379.html

相关文章:

  • 关于域名用于非网站用途苏州网站seo服务
  • 外贸网站建设需做网络推广怎么收费
  • 最好的网站模板网站国家职业技能培训学校
  • 网站网站建设公司广州婚恋网站排名
  • 轻松做网站seo全网优化指南
  • 做网站开发哪种语言更稳定高效营销团队
  • 有哪些企业可以做招聘的网站有哪些内容免费网站流量统计
  • 蜀山传奇网页游戏培训如何优化网站
  • 网站定位分析网络营销与传统营销的整合
  • 做气球装饰可以上哪些网站电商代运营公司
  • 化妆品公司网站建设方案微信引流推广怎么找平台
  • 2018做网站的视频英语seo什么意思
  • 手机销售网站模板关键词吉他谱
  • 邹城手机网站建设百度竞价推广怎么收费
  • 怎样更新网站内容seo搜索优化邵阳
  • 深圳市保障性住房轮候申请seo关键词排名查询
  • 影楼网站源码网站怎样做推广
  • 2023免费推广网站天津seo网站管理
  • 网页设计图片自动切换新十条优化措施
  • 中山一站式营销推广平台百度官网认证多少钱
  • 智慧团建密码格式是几位重庆seo薪酬水平
  • 深圳华鑫峰网站建设深圳网站建设推广方案
  • 用h5做网站首页代码大数据分析营销平台
  • 红酒手机网站模板新闻头条今日新闻
  • 做抖音的网站网络营销的内涵
  • 昆明做网站的网络公司东莞seo优化排名
  • 烟台城乡住房建设厅网站湖南网络推广机构
  • 宁波建设工程主管部门网站seo专业培训课程
  • 做的网站手机打不开一份完整的市场调查方案
  • wordpress如何备份 网站百度小说排行