zoukankan      html  css  js  c++  java
  • 【Uinty3D】3D坦克的基础——攻击

     1 using System.Collections;
     2 using System.Collections.Generic;
     3 using UnityEngine;
     4 
     5 public class TankAttack : MonoBehaviour
     6 {
     7     //创建一个物体
     8 
     9     //(发射3D发射子弹)
    10 
    11     //获取需要发射的物体
    12 
    13     public GameObject shell;
    14 
    15     //获取键盘上的某个按键 空格键
    16 
    17     public KeyCode firekey = KeyCode.Space;
    18 
    19     //物体发射的位置
    20 
    21     public Transform firePos;
    22 
    23     //物体发射的速度
    24     public float shellSpeed = 30f;
    25 
    26     // Use this for initialization
    27     void Start()
    28     {
    29         //在Start函数中
    30 
    31         //获取物体发射的位置
    32 
    33 
    34         firePos = transform.Find("FirePosition");
    35     }
    36     void Update()
    37     {
    38         //在Updata函数中
    39 
    40         //判断是否为空格键
    41 
    42         if (Input.GetKeyDown(firekey))
    43         {
    44             //在firePos处创建物体
    45             GameObject obj = GameObject.Instantiate(shell, firePos.position, firePos.rotation) as GameObject;
    46             //给物体一个速度
    47 
    48             obj.AddComponent<Rigidbody>().velocity = obj.transform.forward * shellSpeed;
    49         }
    50 
    51 
    52     }
    53 }
  • 相关阅读:
    并查集
    归并排序
    树的操作
    活动安排
    动态规划-股票交易
    网络流
    linux 展开
    linux 反引号、单引号、双引号
    linux 命令行快捷键
    判断一个点是否在三角形内部和边界上
  • 原文地址:https://www.cnblogs.com/Whiteying/p/10101120.html
Copyright © 2011-2022 走看看