Unity Udexreal开发插件包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
820 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunActiveSample : MonoBehaviour
{
public GameObject Bullet;
[SerializeField]
private Transform barrelLocation;
[SerializeField]
private float destroyTimer = 2f;
[SerializeField]
private float shotPower = 500f;
void Start()
{
if (barrelLocation == null)
{
barrelLocation = transform;
}
}
public void FireGun()
{
GameObject BulletHead;
// Create a bullet and add force on it in direction of the barrel
BulletHead = Instantiate(Bullet, barrelLocation.position, barrelLocation.rotation);
BulletHead.GetComponent<Rigidbody>().AddForce(barrelLocation.forward * shotPower);
Destroy(BulletHead, 3);
}
}