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

【Unity每日一记】进行发射,位置相关的方法总结

在这里插入图片描述


👨‍💻个人主页:@元宇宙-秩沅

👨‍💻 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅!

👨‍💻 本文由 秩沅 原创

👨‍💻 收录于专栏unity每日一记

🅰️推荐文章


⭐【软件设计师高频考点暴击】

⭐【Unityc#专题篇】之c#系统化大礼包】

⭐【unity数据持久化】数据管理类_PlayerPrfs

⭐【unity本站最全系列】unity常用API大全一篇文章足以
在这里插入图片描述


前言

今天我们主要介绍啊以下2个进行发射的方法

1.通过面板上发射的位置来进行发射
2.通过代码应用我们向量相关的知识点来进行发射


文章目录

    • 🅰️推荐文章
    • 前言
    • 🎶(==A==) 通过面板设置发射位置进行发射
    • 🎶(==B==) 通过向量相关代码设置位置进行发射
    • 🎶(==C==) 通过向量相关进行多种子弹数量类型的发射
    • 🅰️系统路线学习点击跳转



🎶(A 通过面板设置发射位置进行发射


在这里插入图片描述
在这里呢我们在主物体上设置了3个子对象啊这 3个子对象的位置就是用来发射的 3个位置

那么这里就是我们通过面板上设置发射位置


🎶(B 通过向量相关代码设置位置进行发射


在这里插入图片描述
知识点为向量的加减


🎶(C 通过向量相关进行多种子弹数量类型的发射


在这里插入图片描述
😶‍🌫️步骤:


1.设置选择子弹类型的枚举类型
2.封装按键相关api按键为1到 4和空格作用为1到 4是选择子弹数量类型,空格则是发射键
3.而后根据枚举类型进行子弹发射的实例化封装通过向量加减来实现发射位置的偏移,通过向量的4元数旋转来实现发射位置的旋转偏移,


😶‍🌫️涉及口诀:
位置-位置=位置
4元数*4元数=旋转角度

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//-------------------------------------
//—————————————————————————————————————
//___________项目:       ______________
//___________功能:向量相关控制子弹发射
//___________创建者:秩沅_______________
//_____________________________________
//-------------------------------------//首先选择子弹发射的数量类型,我们在这里设置枚举类型 
public enum Shoot_Type
{one,    //一个two,    //两个mutiply,//多个around  //围绕
}public class Shoot : MonoBehaviour
{public Shoot_Type type;public GameObject bullet; //子弹public int i = 10;void Start(){}// Update is called once per framevoid Update(){if(Input.GetKeyDown(KeyCode.Alpha1)) {type = Shoot_Type.one;}else if(Input.GetKeyDown(KeyCode.Alpha2)){type = Shoot_Type.two ;}else if (Input.GetKeyDown(KeyCode.Alpha3)){type = Shoot_Type.mutiply ;}else if (Input.GetKeyDown(KeyCode.Alpha4)){type = Shoot_Type.around ;}else if (Input.GetKeyDown(KeyCode.Space )){Fire();}}public void Fire(){switch (type){case Shoot_Type.one:Instantiate(bullet, transform.position, transform.rotation );break;case Shoot_Type.two:Instantiate(bullet, transform.position-Vector3 .right *2, transform.rotation);Instantiate(bullet, transform.position+Vector3.right * 2, transform.rotation);break;case Shoot_Type.mutiply:Instantiate(bullet, transform.position, transform.rotation);Instantiate(bullet, transform.position - Vector3.right, transform.rotation * Quaternion.AngleAxis(-10, Vector3.up ));Instantiate(bullet, transform.position - Vector3.right*2, transform.rotation * Quaternion.AngleAxis(-20, Vector3.up ));Instantiate(bullet, transform.position + Vector3.right, transform.rotation * Quaternion.AngleAxis(10, Vector3.up));Instantiate(bullet, transform.position + Vector3.right * 2, transform.rotation * Quaternion.AngleAxis(20, Vector3.up));break;case Shoot_Type.around:Instantiate(bullet, transform.position, transform.rotation);for (int i = 0; i < 180; i+=10){Instantiate(bullet, transform.position - Vector3.right, transform.rotation * Quaternion.AngleAxis(-i, Vector3.up));Instantiate(bullet, transform.position - Vector3.right, transform.rotation * Quaternion.AngleAxis(i, Vector3.up));}break;default:break;}}
}

🅰️系统路线学习点击跳转


⭐【Unityc#专题篇】之c#进阶篇】

⭐【Unityc#专题篇】之c#核心篇】

⭐【Unityc#专题篇】之c#基础篇】

⭐【Unity-c#专题篇】之c#入门篇】

【Unityc#专题篇】—进阶章题单实践练习

⭐【Unityc#专题篇】—基础章题单实践练习

【Unityc#专题篇】—核心章题单实践练习


你们的点赞👍 收藏⭐ 留言📝 关注✅是我持续创作,输出优质内容的最大动力!


在这里插入图片描述


http://www.lryc.cn/news/132107.html

相关文章:

  • MISRA 2012学习笔记(3)-Rules 8.4-8.7
  • centos7组件搭建
  • webpack5和webpack4的一些区别
  • 攻防世界-fileclude
  • 深度学习的“前世今生”
  • 第一百一十九回 如何通过蓝牙设备读写数据
  • linux:Temporary failure in name resolutionCouldn’t resolve host
  • C 语言的 sprintf() 函数
  • 李沐pytorch学习-卷积网络及其实现
  • 记录:win10物理机ping不通虚拟机上的docker子网(已解决)
  • 深入浅出Pytorch函数——torch.nn.init.kaiming_normal_
  • D. Anton and School - 2
  • xcode把包打到高版本的iPhone里
  • PMP项目管理考试小结
  • 【NAS群晖drive异地访问】使用cpolar远程访问内网Synology Drive「内网穿透」
  • 【傅里叶级数与傅里叶变换】数学推导——2、[Part2:T = 2 π的周期函数的傅里叶级数展开] 及 [Part3:周期为2L的函数展开]
  • 【IMX6ULL驱动开发学习】06.DHT11温湿度传感器驱动程序编写与测试
  • sip开发从理论到实践,让你快速入门sip
  • 十三、Linux中必须知道的几个快捷键!!!
  • Django进阶-文件上传
  • clickhouse-数据导入导出方案
  • [JavaWeb]【一】入门JavaWeb开发总概及HTML、CSS、JavaScript
  • Python自动化小技巧18——自动化资产月报(word设置字体表格样式,查找替换文字)
  • FFmpeg5.0源码阅读——VideoToobox硬件解码
  • IDEA 中Tomcat源码环境搭建
  • MATLAB | 七夕节用MATLAB画个玫瑰花束叭
  • 嵌入式开发之configure
  • 深入浅出Pytorch函数——torch.nn.Module
  • 【100天精通python】Day38:GUI界面编程_PyQt 从入门到实战(中)_数据库操作与多线程编程
  • STM32--TIM定时器(3)