获取枪的方向,在枪口处射击
来源:互联网 发布:文件夹图标制作软件 编辑:程序博客网 时间:2024/04/29 07:28
写完之后才发现都是一屏幕中心为准星,以摄像机方向为射击方向。不过既然写都写了,说不定以后还会用到,就传上来吧。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour {
public GameObject buttle;
private Vector3 rotate;
private Vector3 dir;
public Transform pos;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
rotate = this.transform.rotation.eulerAngles;
float a = Mathf.Cos(Mathf.PI * rotate.x / 180) * Mathf.Sin(Mathf.PI * rotate.y / 180);
float b = -Mathf.Sin(Mathf.PI * rotate.x / 180);
float c = Mathf.Sqrt(1 - a * a - b * b);
if(rotate.y>90&&rotate.y<270)
{
c = -c;
}
Debug.Log(rotate);
dir = new Vector3(a, b, c);
Debug.Log(dir);
if (Input.GetButtonDown("Fire1"))
{
GameObject buttle1= Instantiate(buttle,pos.position,
Quaternion.identity);
buttle1.GetComponent<Rigidbody>().velocity =dir*5000*Time.deltaTime;
Debug.Log("Shoot!");
}
}
}
- 获取枪的方向,在枪口处射击
- unity在shader中获取当前摄像机的方向向量
- 获取状态栏的方向
- 我们的方向在......
- 一个方向控制射击小游戏的代码分析!(AS1.0)
- android 获取屏幕的方向
- 获取Android设备的方向
- android 获取屏幕的方向
- 获取Android设备的方向
- 获取Android设备的方向
- 获取Android设备的方向
- JavaScript 方向键值的获取
- android 获取屏幕的方向
- 获取Android设备的方向
- 获取所选对象在某个轴方向上的最大值、最小值和中间值
- 在思考自己的方向
- 我的方向在哪里
- 嵌入式的方向在哪里
- 多系统对接的痛点
- JS正则表达式入门
- SAP问题处理总结
- 树莓派体验4
- angularJs 之 Scope(作用域)
- 获取枪的方向,在枪口处射击
- CPP_Basic_Code_P10.1-PP10.10.8
- 发现个Mac上 好玩的快捷键 苹果图标快捷键
- 树莓派体验5
- CCNA的第一天 简单命令 常用快捷键
- 练习题 No.14 STL中的最大堆
- 浅论H5游戏的研发技术及周期
- 面向对象和面向过程有什么区别
- 方法参数(String... strings)