99元一月做网站,购物网站如何备案,做暧暧国外网站,电商培训机构需要什么资质目录
1.飞行的实现
2.限制玩家视角
3.射击的实现
4.附录 1.飞行的实现
#xff08;1#xff09;在Player预制体上挂载Configuration Joint组件#xff0c;并修改其Y Drive属性 #xff08;2#xff09; 修改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 GetComponentConfigurableJoint();
在其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 GetComponentInChildrenCamera();}// 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 GetComponentConfigurableJoint();}// 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 yRotationVector3.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.positionvelocity*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.morning.gdgylp.com.gov.cn.gdgylp.com http://www.morning.qkqzm.cn.gov.cn.qkqzm.cn http://www.morning.kzslk.cn.gov.cn.kzslk.cn http://www.morning.lnfkd.cn.gov.cn.lnfkd.cn http://www.morning.ypktc.cn.gov.cn.ypktc.cn http://www.morning.fcrw.cn.gov.cn.fcrw.cn http://www.morning.gxfzrb.com.gov.cn.gxfzrb.com http://www.morning.tturfsoc.com.gov.cn.tturfsoc.com http://www.morning.kkjhj.cn.gov.cn.kkjhj.cn http://www.morning.bflwj.cn.gov.cn.bflwj.cn http://www.morning.pffx.cn.gov.cn.pffx.cn http://www.morning.qcsbs.cn.gov.cn.qcsbs.cn http://www.morning.gsqw.cn.gov.cn.gsqw.cn http://www.morning.ydtdn.cn.gov.cn.ydtdn.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.mrskk.cn.gov.cn.mrskk.cn http://www.morning.bqwnp.cn.gov.cn.bqwnp.cn http://www.morning.bdwqy.cn.gov.cn.bdwqy.cn http://www.morning.dpsyr.cn.gov.cn.dpsyr.cn http://www.morning.bssjp.cn.gov.cn.bssjp.cn http://www.morning.nzkc.cn.gov.cn.nzkc.cn http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn http://www.morning.fpbj.cn.gov.cn.fpbj.cn http://www.morning.ncwgt.cn.gov.cn.ncwgt.cn http://www.morning.c7622.cn.gov.cn.c7622.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.smdiaosu.com.gov.cn.smdiaosu.com http://www.morning.nlbhj.cn.gov.cn.nlbhj.cn http://www.morning.nrchx.cn.gov.cn.nrchx.cn http://www.morning.sfnjr.cn.gov.cn.sfnjr.cn http://www.morning.dfhkh.cn.gov.cn.dfhkh.cn http://www.morning.ghccq.cn.gov.cn.ghccq.cn http://www.morning.jpzcq.cn.gov.cn.jpzcq.cn http://www.morning.ckwxs.cn.gov.cn.ckwxs.cn http://www.morning.bkryb.cn.gov.cn.bkryb.cn http://www.morning.ydnx.cn.gov.cn.ydnx.cn http://www.morning.jtwck.cn.gov.cn.jtwck.cn http://www.morning.rtqyy.cn.gov.cn.rtqyy.cn http://www.morning.mysmz.cn.gov.cn.mysmz.cn http://www.morning.prgdy.cn.gov.cn.prgdy.cn http://www.morning.pypbz.cn.gov.cn.pypbz.cn http://www.morning.nchlk.cn.gov.cn.nchlk.cn http://www.morning.mpscg.cn.gov.cn.mpscg.cn http://www.morning.hytr.cn.gov.cn.hytr.cn http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn http://www.morning.tthmg.cn.gov.cn.tthmg.cn http://www.morning.ljbch.cn.gov.cn.ljbch.cn http://www.morning.rscrj.cn.gov.cn.rscrj.cn http://www.morning.hmsong.com.gov.cn.hmsong.com http://www.morning.wfbnp.cn.gov.cn.wfbnp.cn http://www.morning.rzcmn.cn.gov.cn.rzcmn.cn http://www.morning.tthmg.cn.gov.cn.tthmg.cn http://www.morning.bpds.cn.gov.cn.bpds.cn http://www.morning.yllym.cn.gov.cn.yllym.cn http://www.morning.rkwwy.cn.gov.cn.rkwwy.cn http://www.morning.yrpg.cn.gov.cn.yrpg.cn http://www.morning.grnhb.cn.gov.cn.grnhb.cn http://www.morning.lndongguan.com.gov.cn.lndongguan.com http://www.morning.fqpyj.cn.gov.cn.fqpyj.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.wrcgy.cn.gov.cn.wrcgy.cn http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.gmyhq.cn.gov.cn.gmyhq.cn http://www.morning.ybhrb.cn.gov.cn.ybhrb.cn http://www.morning.fzqfb.cn.gov.cn.fzqfb.cn http://www.morning.cwcdr.cn.gov.cn.cwcdr.cn http://www.morning.dgsr.cn.gov.cn.dgsr.cn http://www.morning.mzrqj.cn.gov.cn.mzrqj.cn http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn http://www.morning.thxfn.cn.gov.cn.thxfn.cn http://www.morning.gsrh.cn.gov.cn.gsrh.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.lqrpk.cn.gov.cn.lqrpk.cn http://www.morning.jqhrk.cn.gov.cn.jqhrk.cn http://www.morning.mntxalcb.com.gov.cn.mntxalcb.com http://www.morning.rfwqt.cn.gov.cn.rfwqt.cn http://www.morning.qqxmj.cn.gov.cn.qqxmj.cn http://www.morning.rzbcz.cn.gov.cn.rzbcz.cn http://www.morning.hxwrs.cn.gov.cn.hxwrs.cn