NewN_UAVPlane/Assets/Zion/Scripts/Adam/Components/TestTTT.cs

30 lines
759 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestTTT : MonoBehaviour
{
public GameObject bulletPrefab; // 子弹预制体
public Transform firePoint; // 发射点
public float bulletForce = 20f; // 子弹速度
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("w"))
{
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
bullet.SetActive(true);
Rigidbody rb = bullet.GetComponent<Rigidbody>();
rb.AddForce(firePoint.forward * bulletForce, ForceMode.Impulse);
}
}
}